Send Listing of Directory or Folder To Notepad For Easy Printing

Contributor Icon Contributed by davak Date Icon January 26, 2004  
Tag Icon Tagged: Windows

Windows does not have an easy way to print out the contents of a directory or folder. This shortcut makes the task simple.


Often I need to print or email somebody a listing of a folder’s contents. Windows does not have an easy way to do this.

The creation of this file will make this task very simple.

1. Open Notepad
2. Copy and paste the following text:

@echo off
if EXIST %1 goto start
echo Drag and drop any file onto this program to grab its parent directory listing.
pause
goto end
:start
echo "%~dp1"
dir "%~dp1" > dir.txt || pause
start dir.txt
:end

3. Under the File menu select Save as
4. As you want to save this to your desktop, browse to the appropriate location.
5. Under filename type dirlist.cmd
6. Under Save as type select All Files
7. Click OK

A file called dirlist.cmd should be created on your desktop. Clicking this file will just give you the echo message and not do anything productive.

To use your new tool, drag any file onto this newly created item on your desktop. The directory contents of that file’s folder will be opened in notepad.

For example, to print out a listing of my toolbar directory, I would navigate to my toolbar directory and drag any file in the toolbar directory to the dirlist.cmd file.

This produces the following:

    Volume in drive C is ALEX
    Volume Serial Number is 3943-16E3

    Directory of C:\Toolbar

    10/31/2001 10:33 PM

    .
    10/31/2001 10:33 PM ..
    11/18/2003 09:23 PM 1,127 ALEX (C).lnk
    01/20/2002 12:18 PM 1,122 WINSLOW (D).lnk
    01/27/2002 02:26 PM 1,142 CD Drive.lnk
    11/01/2001 06:55 PM 362 Shortcut to My Pictures.lnk
    11/01/2001 06:55 PM 347 Shortcut to My Music.lnk
    11/01/2001 06:58 PM 252 Shortcut to My Documents.lnk
    6 File(s) 4,352 bytes
    2 Dir(s) 12,076,679,168 bytes free

I do not know where I first saw code similar to this… but hats off to the original author. The only trick is to remember to drag any file from the folder in question onto your dirlist.cmd file.

Previous recipe | Next recipe |
 
  • davak
    Trojan at mameworld.info made the following suggestion for creating a barebones listing...



    Change

    dir "%~dp1" > dir.txt || pause

    to

    dir /b "%~dp1" > dir.txt || pause




    Original thread:
    http://www.mameworld.info/ubbthreads/showthreaded.php?Cat=&Number=36808&page=&view=&sb=5&o=&vc=1
  • zixp
    There is a much easier way to get your directory listing into a text file:

    Open the command line
    "cd" to the directory you want
    type "dir >> "C:Your_Text_File.txt"

    Thats it, it will create your text file with the directory listing. Better yet, you can use ">>" with any other commands, all it does is direct the output to a text file.
  • Anonymous
    Does not work! I created the text file, i tried to save it as said via Save As and it still added the .txt to the file name on desktop, i renamed it as a .cmd file and no go nothing, the Open With... window appears every time i double-click it, if i drag a file onto it the file just re-appears on the desktop, no .txt file created.

    Sorry, does not work here with Win98SE.
    What's up?
  • Anonymous
    Excellent tool, my son explained I didn't have to double clk the icon to get it to work correctly. Nice site (Tech Recipies) thanks bobo
blog comments powered by Disqus