J
Josh Charles
I have a bit of code I'm working on where I need to seperate the
directories from the files. Currently, it's processing the first
three properly and skipping the rest.
I'm running this on windows.
Here is the code:
def GetFolders
rtn =3D ""
Dir.foreach( @userFilePath ) do |x|
=09if FileTest.directory?( x )=20
=09 rtn +=3D "<Folder name=3D\"" + x + "\" />" unless x <=3D ".."
=09end
end
return rtn
end
=09
def GetFiles
rtn =3D ""
Dir.foreach( @userFilePath ) do |x|
rtn +=3D "<File name=3D\"" + x + "\" size=3D\"000\" />" unless
FileTest.directory?( x )
end
return rtn
end
It gives the output of:
<Folders>
<Folder name=3D"test"/>
</Folders>
<Files>
<File name=3D"404.html" size=3D"000"/>
<File name=3D"500.html" size=3D"000"/>
<File name=3D"asdf" size=3D"000"/>
<File name=3D"asdnt.txt" size=3D"000"/>
<File name=3D"silk" size=3D"000"/>
<File name=3D"thingy.html" size=3D"000"/>
</Files>
The actual directory contains:
<DIR> .
<DIR> ..
<FILE> 404.html
<FILE> 500.html
<DIR> asdf
<FILE> asdnt.txt
<DIR> silk
<DIR> test
<FILE> thingy.html
4 File(s) 567 bytes
5 Dir(s) 22,350,041,088 bytes free
I'm still learning ruby, so I've probably written something incorrectly...
Josh
directories from the files. Currently, it's processing the first
three properly and skipping the rest.
I'm running this on windows.
Here is the code:
def GetFolders
rtn =3D ""
Dir.foreach( @userFilePath ) do |x|
=09if FileTest.directory?( x )=20
=09 rtn +=3D "<Folder name=3D\"" + x + "\" />" unless x <=3D ".."
=09end
end
return rtn
end
=09
def GetFiles
rtn =3D ""
Dir.foreach( @userFilePath ) do |x|
rtn +=3D "<File name=3D\"" + x + "\" size=3D\"000\" />" unless
FileTest.directory?( x )
end
return rtn
end
It gives the output of:
<Folders>
<Folder name=3D"test"/>
</Folders>
<Files>
<File name=3D"404.html" size=3D"000"/>
<File name=3D"500.html" size=3D"000"/>
<File name=3D"asdf" size=3D"000"/>
<File name=3D"asdnt.txt" size=3D"000"/>
<File name=3D"silk" size=3D"000"/>
<File name=3D"thingy.html" size=3D"000"/>
</Files>
The actual directory contains:
<DIR> .
<DIR> ..
<FILE> 404.html
<FILE> 500.html
<DIR> asdf
<FILE> asdnt.txt
<DIR> silk
<DIR> test
<FILE> thingy.html
4 File(s) 567 bytes
5 Dir(s) 22,350,041,088 bytes free
I'm still learning ruby, so I've probably written something incorrectly...
Josh