Add a context menu option to list all files in a folder and save it as text file

okthen has commented here with an easier way if you know registry :
Go to the Folder tree My Computer\HKEY_CLASSES_ROOT\Folder\shell\ Right Click and select New»Key name the key “List Files and Folders” Now add another key to it named command. Go to the Default on right panel and double click on Default REG_SZ and paste
cmd /c dir %1 /a /b >%1\list.txt
Thanks okthen

Well the title explains it all. What we are going to do is add an option like this to the context menu (Right Click) of all folders. When you click on that the result of a dir command (all files and folders in that Filder) are listed and saved to a file name Listofile.txt in the same Folder. This file is then automatically opened. All this can be done by using simple tools available in windows itself. If you need to know more about batch files please read the . Consider reading it first if you don’t know what a batch file is.

Step 1 : Create a batch file

The required commands saved in a batch fileCreate a batch file named “ListFile.bat” at “C:\Program Files\Mine\” folder (of course you can use any name and any location). Noe Right click on it and select Edit. The file will now be opened in NotePad. Enter the following lines as seen in the screen shot here. This step is common to both methods – using registry and using folderoptions menu. The commands are :

cd %1
dir /a /p /o:gen>listofile.txt
start “List of Files” notepad listofile.txt
exit

First line the batch file accepts the path of directory you clicked and changes the directory - cd to it. %1 is the argument.The second line produces the list of files and directories and redirects (>) to a file in that directory named listofile.txt , “start” starts notepad as a new process independent of the batch file and opens the listofile.txt .If you simply type notepad the process will be child of the batch file the result can be observed if you try it.

Adding an option to folder Menu

Easy way – Folder options

Goto Folder Options and select File types select New to add the new action to folder context menu.

Files listed stored automatically into a text file
In the Actions add List Files and Folders, in the Application used to do the action: add “C:\Program Files\Mine\Listfile.bat” “%1″ including the quotes. The %1 tells Windows to send the Path of the folder to our batch file when List Files and Folders option is selected.
list-files-show-add-folder-option-command.gif

Just restart Windows or Restart Windows Explorer and you will see the added options.

Hard Way – Registry Editing

OK so if you want a brief intro to editing registry please read the previous posts – , . Now Go to the Folder tree My Computer\HKEY_CLASSES_ROOT\Folder\shell\ Right Click and select New»Key name the key “List Files and Folders” Now add another key to it named command. Go to the Default on right panel and double click on Default REG_SZ and paste “C:\Program Files\Mine\Listfile.bat” “%1″ and save it.

Registry Key to be added.

So the adding section is finished both the hard way and the easy way.

Result

Since all the hard work is done now lets go for the piece of cake. Right Click on any folder and select List Files and Folders. You will see the file named Listofiles.txt opened and the list of files inside that. The file is also saved inside the folder you selected.

File produced as the output listofile
This as can be seen is the result produced by dir command. This is really simple but can help us understand and tackle Windows our way. Do experiments with other options also. And if you have any doubts just contact me .

You may also want to know

Some related articles you may like :

  1. Correction to the list files and folders from a directory to a file
  2. Batch files to automate tasks in Windows environment – tutorial
  3. What are the hidden files and folders
  4. How to add your favourite picture to Windows default wallpaper list ?
  5. Save web pages as mht file for better management of documents
  6. View system files (super hidden) in Explorer
  7. How to clear full internet history from Internet Explorer
  8. Universal file manager and viewer – one program for all your file types

This entry was posted in Windows and tagged Command Prompt/Shell, Customize, File, Tips. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

16 Comments

  1. Posted April 30, 2011 at 5:51 PM | Permalink

    I was just looking for this info for some time. After hours of continuous Googleing, at last I got it in your site. I wonder what’s the lack of Google strategy that don’t rank this kind of informative websites in top of the list. Generally the top websites are full of garbage.

  2. jmadden93
    Posted November 22, 2010 at 1:13 AM | Permalink

    This is really useful. Anyone know how to do this in Windows 7 64bit?

  3. Posted June 15, 2010 at 8:42 PM | Permalink

    Very Good Blogpost. Would you thoughts if I take a tiny snippets of your post and naturally link it to your blogposts??

  4. Posted April 23, 2010 at 1:01 AM | Permalink

    Hi Jack, I have come up with the sokution to your problem.

    Use the following string as default value for your command Key cmd /c cd %1&&lstfrmt>listfile.txt&&start notepad listfile.txt

    Paste this lstfrmt.bat file in your C:\WINDOWS folder (or any other folder in that is included in the PATH variable)

    Screenshot : http://www.exnol.com/wp-content/uploads/2007/tmp/list-file-thumb.jpg
    Screenshot : http://www.exnol.com/wp-content/uploads/2007/tmp/list-files-registry-value.jpg

  5. Posted April 19, 2010 at 8:17 PM | Permalink

    To Jack.
    The dir command can’t solve your problem.
    You can do it with wList, click my nick and get it.

    wList can add backslash character to folder names as you wish.
    Go: List Style – Customize – and set combo: Folder Item

    Regards,
    Piotr

  6. Posted April 9, 2010 at 7:46 AM | Permalink

    Got it Jack. Will post it tomorrow.

  7. Posted April 7, 2010 at 9:35 AM | Permalink

    Hi Montec, thanks for your comment. I am currently trying to do that using “find” command in Command prompt. Please subscribe to the comments so that you will get updates when the solution is found. The email subscribe form is just below the comment form.

  8. jack
    Posted April 5, 2010 at 8:28 AM | Permalink

    very good tip, but how do u able to display folder symbol on the end of a direcory…

    how do u able to make the dir command to display folder with a slash, dot, or folder symbol on the end to indicate it is a directory???

    ex:
    dir C:/Folder it will show the folder as below

    folder1/ or make it display as folder1.. , etc
    folder2/
    text 1.txt
    text 2.txt

  9. Montec
    Posted April 5, 2010 at 2:27 AM | Permalink

    Me
    Use Windows Enabler at http://www.freewarefiles.com/Windows-Enabler_program_980.html

    This is a great little program but use it CAREFULLY.

  10. me
    Posted March 24, 2010 at 3:45 AM | Permalink

    hi
    how do i remove the item from the context menu? the “remove” button is greyed out in the folder options dialog.

  11. Posted November 27, 2009 at 6:36 AM | Permalink

    Great. see great shareware for doing that – wList
    http://www.sharktime.com/us_wList.html

    It works similar to dir command but in a window.
    It automatically adds list option to right click menu.

  12. Posted April 6, 2008 at 1:18 PM | Permalink

    Hi OKTHEN
    thank you very much.
    BTW please contact me if you don’t mind .. I don’t have your email address

  13. okthen
    Posted April 5, 2008 at 4:08 AM | Permalink

    sorry i messed up awhile back
    cmd /c dir %1 /a /b >%1\list.txt

    would not only be unable to list files in folders with long file names but also it would not be able to output the list.txt to a folder with a long file name in order for it to work with long folder names, u need to use quotes around the %1′s also, if you use >> instead of > it will append to any existing list.txt in the folder you are catalogging instead of replacing the text file with a new one

    if you want to append to a pre-existing list.txt when one already exists in the output folder then use:

    cmd /c dir “%1″ /a /b /s >>”%1″\list.txt

    or if you want it to replace a possibly pre-existing list.txt in the same output folder every time

    cmd /c dir %1 /a /b >%1\list.txt

    ————————————————
    if you dont wanna screw around in regedit
    ————————————————
    then copy the following to a notepad document and then save it (where you can find it to click on) as listfiles.reg (NOTE make sure when u are in the save as dialog box in notepad you must use quotes around “listfiles.reg” otherwise it will loose its .reg extension and be useless)

    [Start copy below this line]

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\Folder\shell\Make FileList]

    [HKEY_CLASSES_ROOT\Folder\shell\Make FileList\command]
    @=”cmd /c dir \”%1\” /a /b /s >>\”%1\”\\list.txt”

    [End copy above this line]

    once the above is saved into a file called “listfiles.reg”
    find the file in whatever folder you put it in
    Right click on the file, left click on Merge
    a box will ask are you sure? Yes/No click Yes

    now you have a new command available “Make FileList”
    when you right click any folder you will see this option

    if you left click on the option it will then create a new file within that folder called list.txt which contains the contents of that folder as it was each time you told it to make a list

    i realised awhile back i did not afford for long folder names but only now decided to correct it since i want to use almost the exact same thing to create a context deltree command (for quick erasure of files when i want it without using 1: shift+delete or 2: telling recycle bin to never be active keep files)

  14. Posted February 16, 2008 at 11:26 PM | Permalink

    Thanks ‘okthen’ its better and easy…

  15. okthen
    Posted February 16, 2008 at 11:11 PM | Permalink

    oops messed up its

    cmd /c dir %1 /a /b >%1\list.txt

  16. okthen
    Posted February 16, 2008 at 11:06 PM | Permalink

    Go to the Folder tree My Computer\HKEY_CLASSES_ROOT\Folder\shell\ Right Click and select New»Key name the key “List Files and Folders” Now add another key to it named command. Go to the Default on right panel and double click on Default REG_SZ and paste

    cmd /k dir %1 /a /b /s >%1\list.txt

    exit registry editor

2 Trackbacks

  1. By How to Manage Your Recordings « Earbirding.com on March 14, 2010 at 3:08 AM

    [...] nifty trick I learned from this webpage was how to add a “Print Directory Listing” option to my Windows right-click menu.  [...]

  2. [...] think you all remember OKTHEN, the one who told us all an easy way to list files and folders in a directory into a file through a context menu. He posted it as a comment. Well last day he commented on the post to correct some mistakes in the [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>