Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting a list of files in a folder

Status
Not open for further replies.

bujin

MIS
Oct 2, 2000
144
GB
Hi

A colleague of mine in work today asked me if there was a way of outputting the filenames of all files a specified folder to a text file so that she could copy and paste the filenames into the document she was writing, rather than have to type the names out (there are quite a lot of them!).

Is there a way to do this in Windows? The only way I could think of was to resort to the DOS Prompt, find the folder then use the following line:

dir /a-h-s-d /on /b >n:\mywork\filelist.txt

Is there an easier way?
 
Hello, bujin.

This is how I make it to the rightclick context menu for this maintenance job.

[1] Click out the Folder Options (from explorer or start|settings).
[2] From the registered file types, locate "Folder". Click on it and choose Edit.
[3] Below the Action window, click on the button "New".
[4] Give the new action a name. I use for instance "List folder contents".
[5] In the action input box, enter the action, practically the one you are using. I use :

c:\windows\command.com /c dir %1 /s/o:gn > %1_dir.txt

You can use slightly different dir switches and filename.
[6] Close out Folder Options by OK's.

What are the advantages of all the above?
[7] It will do the dir listing automatically once you point the mouse over the folder you want to list the contents by rightclick and choose "List folder contents". It is done all along within the Explorer environment. This avoid the annoyance of CD's to the directory in dos box or type in the long directory path.
[8] It will creates the text file name with the convention as follows:

folder to list: ...\upper_level\myfolder
listfile: ...\upper_level\myfolder_dir.txt

at the same level of the myfolder, so that you can immediately locate it without the need to locating it elsewhere.

In any case, apart from the shortfilename eventually get its way into %1_dir.txt, the above setting is the best possible way to get the job done.

regards - tsuji
 
has a $20US shareware app called clipmate. It gathers a cumulative collection of documents that would otherwise normally have to be copied to and pasted from the clipboard one at a time.

Besides gathering copies of text and graphics, it can also copy and make available a text listing representation (alternate format) of copied files known as HDROP. It is also possible to edit the contents prior to pasting:

HDROP Expansion Process

When you copy from Windows Explorer, there is a format called HDROP that enables cut/copy/paste within Explorer – and possibly other applications that make use of the HDROP. But there's no human-readable listing of the files. However, there IS a listing of the files buried inside of the HDROP data.

Under the Edit menu in Clpimate, there is a command to extract the filenames and make a new TEXT component of the data.

for one-offs use: Edit | Convert file pointer to text

If you find that you always want the TEXT to be generated automatically when HDROP is encountered, select the "Automatically expand HDROP…" option.

for Automatic Conversion setup: Config | User Preferences | Edit Rules | Automatically expand HDROP (check box)

Thereafter, to copy to a Word Document, for example, you would highlight the clip of interest in Clipmate, and specify the format if more than one is available to essentially put that content back on the clipboard. In Word or other HDROP compatible app, you invoke Edit | Paste Special (select unformatted text option) to paste your file list as text.
 
Here's one very similar to tsuji's:

If you are comfortable (and careful!) with editing your registry, you can easily add the option "Print" to your right-click content menu (change the drive letter/printer port used below if yours is different):
Open a new document using a text editor and type:

CD %1
DIR>LPT1

then save it as PRINTDIR.BAT in your Windows\Command folder.

Find this new file in Explorer, right-click on it and select Properties. In the Program tab, turn on the Close on Exit option, choose Minimized from the Run list, then click Apply.

Go to Start>Run, type in regedit and click OK. Open My Computer\HKEY_CLASSES_ROOT\DIRECTORY\shell.
Select New from the Edit menu, and then select Key. Type Print for the name of this new key, and press Enter.
Highlight the new Print key, select New from the Edit menu, and then select New again.

Type command for the name of this new key, and press Enter.
Double-click on the (Default) value in the right pane, and type:

C:\Windows\Command\PRINTDIR.BAT
Close regedit.
Now just right-click on a folder icon and choose Print to print its contents, including sub-directories.

reghakr
 
List-Fc adds 'List Folder Contents to folder.txt' to the right click menu. Right click a folder and select 'List Folder Contents to folder.txt'.
 
Thanks all!

I went with tsuji's method - it works quite well! I changed the command line to

c:\windows\command.com /c dir %1 /a-h-s-d /on /b >%1_dir.txt

so that I just get the file names in alphabetical order without all the other information around it.

Thanks again.
 
One problem with the above method is that you can't use it to print the contents of a CD ROM because it will try and fail to write to the CD ROM. So why not use the command line as follows, which will then place it in your temporary directory
c:\windows\command.com /c dir %1 /a-h-s-d /on /b >c:\temp\filelist.txt
Obviously you will need to change the name of previously created filelist.txt files - but that's no hardship.
Many thanks for the tips. Hope this little idea was useful.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top