Results 1 to 10 of 10

Thread: Command line for making a directory list?

Threaded View

  1. #4
    Join Date
    Aug 2006
    Location
    255.255.255.666
    Posts
    2,056

    Lightbulb

    As an addition to what the other fellas said...

    Quote Originally Posted by DeLuk View Post
    From what I've been reading around, to make a list of the files in a folder, the command line is as below, right?

    dir "path to the folder" /b /s > filelist.txt
    The above command would send the output to a text file (if one existed at the same location then it would be overwritten) which would list all the files, folders, sub-folders and their contents as well (due to the /s parameter), located at that path you specify. The list will be bare due to the /b parameter, meaning only the full path/file name will be written, no attributes, time/date/size related info.

    The best way to learn more about a command on the fly is to type the command followed by a space then a forward slash and a question mark. So to learn more about the dir command and its options, simply type: dir /?

    My doubt is, what in the case of the folder for which one wants to create the list of files being named with more than a single word, well like "Documents and Settings" for example; is it also possible to use this command line in such case?

    dir C:\Documents and Settings /b /s > filelist.txt

    Or should it be typed in a different way then, or can it not be used at all, or?...
    Unfortunately the above command would fail as you mentioned as well. Why?
    Because, command line would not be able to make heads and tails of what to do when it hits the first space and it is an invalid path.
    To elaborate, here is what happens:
    dir C:\Documents then a space comes, so command line thinks that is the path, ignores the rest as C:\Documents is not a valid folder path. If you created a folder o nthe C drive and named it 'Documents' the result would be different.
    So what can you do when the path has space or more than 8 characters?
    2 options:

    The Windows Explorer sample file path:
    C:\Documents and Settings\Turco\Desktop\LongFileName.txt

    1) Use the old DOS naming convention of 8.3 file name standard, of course with folders, you would be only using 8 characters for name. Since Documents and Settings has 20 characters not counting the spaces, you have to type the name by using the first 6 characters followed by a tilde and number one: C:\Docume~1\Turco\Desktop\Longfi~1.txt

    ~1 tells the command line to pick the first matching entry. So lets say you have two files at the above target location, one named LongFileName.txt and the other name LongFileType.txt and since you are using the first 6 characters, how would you tell command line which one to pick? The number that comes after the tilde does just that. If you wanted to pick LongFileName.txt you use ~1, for LongFileType.txt would be ~2 since it would come after in an alphabetical order.

    or

    2) Use quotation marks so command line sees the entire path as the path:
    "C:\Documents and Settings\Turco\Desktop\LongFileName.txt"

    so for your example the full command line would read:

    dir "C:\Documents and Settings\Turco\Desktop" /s /b > filelist.txt
    The resulting file will be created wherever the command-line window was opened from (see screenshot).

    Ideally, using variables in the Command Line environment could make things easier. For example instead of typing "C\Documents and Settings\Turco\Desktop", I could also type "%userprofile%\Desktop"
    %userprofile% is a system variable meaning the current user's home directory being C:\Documents and Settings\username. If I logged of and my friend PhilliePhan logged on to my machine (like hell I would let him but lets say so hypothetically), then the %userprofile% would point to C:\Documents and Settings\PhilliePhan.
    %systemdrive% means whichever drive Windows was installed on which generally refers to C drive, but if Windows98 was installed on C, an installation of Windows 2000 was on D and XP which you are running the command line was installed on E, then %systemdrive% for XP would be the root of E drive (E:\).
    %windir% refers to the Windows folder which again mostly commonly refers to C:\Windows.
    %allusersprofile% would be C:\Documents and Settings\All Users
    %temp% refers to C:\Documents and Settings\currentuser\Local Settings\Temp folder.


    Hope this helps you....

    ~TL
    Attached Images Attached Images
    Last edited by TurcoLoco; 11-11-2006 at 03:42 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •