Generate file listing - list contents of a folder

pdanev

Forum Addict
Joined
Oct 4, 2004
Messages
5,645
This has been requested quite a few times - how do I list the contents of a folder in a txt file - with the usual response of using a cmd approach. Needed this today again, and since I never exactly remember the command in cmd, I googled once again, but by mistake found something interesting. I think this is by far the most handy approach, hopefully it hasn't been posted before.

http://www.theeldergeek.com/file_list_generator.htm

Basically you make a bat file, and whenever you right click a folder in windows explorer it gives you a new line with the option to automatically list the contents into a txt file.

Screenshot
FL04.gif
 

smib

is a big honkin' homo
Joined
Aug 31, 2007
Messages
6,465
Location
Connecticut, USA
Car(s)
2010 Mazda3
Very neat find, this will definitely come in handy.
 

Hatmouse

Well-Known Member
Joined
Jun 30, 2005
Messages
4,786
Location
Bay area, California
Car(s)
'03 Civic Si
And for MacOsX and *nix users:

$ls /directory/name > contents

Will list the contents of /directory/path to a file called contents in the current directory.
 

smib

is a big honkin' homo
Joined
Aug 31, 2007
Messages
6,465
Location
Connecticut, USA
Car(s)
2010 Mazda3
I just remembered this vbs a friend of mine made a while back. It creates a directory of whatever drives, local or external, on your computer in a text file.


Copy this into notepad then save it as a .vbs file. It will save the log in the same folder as the script.
on error resume next

set fso = createobject("scripting.filesystemobject")
set WshShell = CreateObject("WScript.Shell")

function getSubs(folder,level)
dim currFolder, subFols
set currFolder = folder

set subFols = currFolder.subfolders

if level = 0 then
logging.writeline folder
end if

for each newFolder in subFols
for intx = 0 to level
logging.write vbtab
next

logging.write "/" & newfolder.name & vbcrlf

for each newFile in newfolder.files
for intx = 0 to level
logging.write vbtab
next

logging.write ">" & newFile.name & vbcrlf
next

call getSubs(newFolder,level+1)
next
end function



Randomize
rndID = cint( Rnd() * 9999 )

while not fso.fileexists(fso.getfile("recurse.vbs").parentfolder & "\" & "h4x0rlogs-" & rndID & ".log")
Randomize
rndID = cint( Rnd() * 9999 )

fso.createtextfile(fso.getfile("recurse.vbs").parentfolder & "\" & "h4x0rlogs-" & rndID & ".log")
wend

set logging = fso.opentextfile(fso.getfile("recurse.vbs").parentfolder & "\" & "h4x0rlogs-" & rndID & ".log",2)

set allDrives = fso.Drives
for each currDrive in allDrives
set currDriveName = currDrive

select case currDriveName.DriveType
case 0: drtype = "Unknown"
case 1: drtype = "Removable"
case 2: drtype = "Fixed"
case 3: drtype = "Network"
case 4: drtype = "CD-ROM"
case 5: drtype = "RAM Disk"
end select

if WshShell.Popup ("Get structure of " & drtype & " " & currDriveName,,"h4x0r Logging",4) = 6 then
set tester = fso.getFolder(currDriveName & "\")
call getSubs(tester,0)
end if
next
wscript.echo "pwn3d"
 

smib

is a big honkin' homo
Joined
Aug 31, 2007
Messages
6,465
Location
Connecticut, USA
Car(s)
2010 Mazda3
Ok I've run into a problem. After making the .bat file and such, the Create File Listing action is now the default for double-click. This of course means that I just keep re-writing the text file instead of opening the folder. Any idea on how to fix this? I don't want to get rid of the action, but I suppose I will if I have to.
 

chaos386

.sa = bad driver!
Joined
Nov 8, 2004
Messages
7,960
Location
Back in Saudia
Car(s)
SEAT Leon FR
And for MacOsX and *nix users:

$ls /directory/name > contents

Will list the contents of /directory/path to a file called contents in the current directory.

And for people who use GNOME, you can add it to the right-click context menu in Nautilus (making it work like the program in the first post). Just save this to ~/.gnome2/nautilus-scripts/ and make it executable:

Code:
#!/bin/bash

quoted=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN {FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)

listing=$(echo $quoted | sed s/\"\ /\"\\n/g)

IFS=$'\n'

for i in $listing
do
ls $(basename $i \") > "contents of $(basename $i \")"
done

^If you right-click on a folder and run that script, it will create a file called "contents of <folder name>" with a listing of the contents. You can even select multiple folders at once, and it'll create a listing for each one. :)
 
Top