Results 1 to 10 of 10

Thread: Command line for making a directory list?

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    3

    Question Command line for making a directory list?

    Hi.

    I have a doubt regarding command lines (using cmd.exe on Windows XP).

    (I only hope it's ok to ask about this here?... In case not, though, I'd then greatly appreciate it if you could please direct me to the appropriate section/forum where I could request for help in regards to my doubt.)

    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

    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?...

    I'm asking because each time I try to use this command line to make a list of the files in a folder named with more than a single word (with spaces in between) I always get the message "File not found." and the resulting filelist.txt is either empty or incomplete (and I'm guessing that must be due to the spaces in the path to the folder?).

    Pardon all of my ignorance (I truly am NOT AT ALL familiar with command lines) and thank you already for any further enlightenment and help.

  2. #2
    Join Date
    Aug 2006
    Posts
    578

    Lightbulb

    Hi DeLuk,

    I'm not sure if this is what you are looking for, but here are a couple batch files that you might want to try/play around with. Both generate long lists and you might wish to include switches to pare them down.

    -- Just copy the items in quotes below to NOTEPAD
    -- Save them to your Desktop as FindFilesA.bat and FindFilesB.bat
    -- Then, just doubleclick on them and your results will pop up in Notepad. When you close notepad, the file will be deleted. So, remember to save it

    @ECHO OFF

    cd %systemdrive%\Documents and Settings\
    dir /a >> %systemdrive%\filelist.txt
    notepad %systemdrive%\filelist.txt
    del /q %systemdrive%\filelist.txt


    This second one adds a couple switches, but is still quite a list:

    @ECHO OFF

    cd %systemdrive%\Documents and Settings\
    dir /a /b /s >> %systemdrive%\filelist.txt
    notepad %systemdrive%\filelist.txt
    del /q %systemdrive%\filelist.txt


    **
    I should add that, if you want to find a more specific folder, you could modify the following:

    cd %systemdrive%\Documents and Settings\User Name\Desired Folder Name for example.......


    Let me know if this helps or if you have any questions.

    Best Luck
    PP
    Last edited by PhilliePhan; 11-09-2006 at 10:29 PM.

  3. #3
    Join Date
    Aug 2006
    Location
    Orlando FL
    Age
    70
    Posts
    1,316
    I have a question in response to your question, DeLuk. Under what circumstances would you need to be able to list files under XP from a command prompt?

  4. #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.

  5. #5
    Join Date
    Aug 2006
    Posts
    578

    Talking

    Quote Originally Posted by TurcoLoco View Post
    If I logged of and my friend PhilliePhan logged on to my machine (like hell I would let him but lets say so hypothetically)
    HA! I'm already logged on and in control via my "Turcolocator" Satanic Control Trojan!!!

    MUHHHHaaHaaaHAAAHAAAHAAAAA!!!



    LOL!!!
    Attached Images Attached Images
    Last edited by PhilliePhan; 11-11-2006 at 06:35 PM.

  6. #6
    Join Date
    Aug 2006
    Location
    255.255.255.666
    Posts
    2,056
    Quote Originally Posted by PhilliePhan View Post
    HA! I'm already logged on and in control via my "Turcolocator" Satanic Control Trojan!!!

    MUHHHHaaHaaaHAAAHAAAHAAAAA!!!

    http://forum.networktechs.com/attach...1&d=1163288069

    LOL!!!

    That explains all the pron and pop-ups on my machine!!!


    ...and hence the reason, not letting you on my machine (directly at least).

    And people call me the hacker, huh, now we all know who the real binary god is!

    ~TL

  7. #7
    Join Date
    Nov 2006
    Posts
    3
    Hi again and thank you all for your replies and help tips and explanations, quite impressive, thank you so much indeed! And once more, pardon all of my ignorance! I really had never before even used the command prompt and didn't really have any notion about how it operates (thus why I wasn't aware that there indeed can't be spaces in command lines, though by then I was already suspecting) yet as a friend had commented with me that by using that command line I could easily get a list of all files stored in any specific directory, so I gave it a try. But as it didn't appear to work as I tried it for a folder named with more than one word, so I came for further enlightenment (as I couldn't quite find an answer to this particular doubt in what I had read around about it so far). And so again, thank you so greatly, all, for your such detailed and most helpful explanations, thank you indeed! (I hope it isn't unpolite if I say special thanks to TurcoLoco?... )


    I would have an additional curiosity now, though, coming from F1's reply:

    Quote Originally Posted by F1 View Post
    Under what circumstances would you need to be able to list files under XP from a command prompt?
    Would that be a hint about there being other ways (possibly easier / more practical) to make such listings under XP?... And if so, would you be so kind as to (again) please enlighten me about?... (Let's say I have all my pictures or all my fonts or all my whatever stored in a folder, and I'd wish to send a list of those to a friend. Would there be alternative ways to create that list, instead of by the command prompt, would that be it?...)


    Also I'd have an additional doubt, coming from TurcoLoco's reply:

    Quote Originally Posted by TurcoLoco View Post
    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.
    By saying that the list will be bare due to the /b parameter, does it mean that it would actually be possible to have such info such as time/date/size also included in the list, if wanted? And if so, which would then be the parameters to use, for having that info being included (especially the size, this might be an interesting addition to have in the list)?... Or, for that, should I just not use the /b parameter, and the list would by default include all that info?... (Checking the options with dir /? I don't think I found my answer there... Or perhaps it's even there and I'm such dork that I can't even recognize it? ) Again, I'd very much appreciate any further enlightenment?...


    And one more time, thank you sincerely, for your kind patience with my noob ignorance and all help!


    P.S. And thank you yet for your good humour! In some way that also always helps making a newcomer feel more "at ease"...

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

    Lightbulb

    Quote Originally Posted by DeLuk View Post
    Hi again and thank you all for your replies and help tips and explanations,....(I hope it isn't unpolite if I say special thanks to TurcoLoco?... )
    Oh no, it wouldn't be impolite at all!

    Also I'd have an additional doubt, coming from TurcoLoco's reply:
    By saying that the list will be bare due to the /b parameter, does it mean that it would actually be possible to have such info such as time/date/size also included in the list, if wanted? And if so, which would then be the parameters to use, for having that info being included (especially the size, this might be an interesting addition to have in the list)?... Or, for that, should I just not use the /b parameter, and the list would by default include all that info?
    Unfortunately, the help included within the command line doesn't have much depth and probably written by the MS geeks who see thing as ONEs and ZEROs all the time and quite possibly be the first to join the BORG civilization.

    Back to Command Line 101 (I am, btw, thinking about creating a sticky on XP Command Line and creating batch files, etc but not sure if it is something that would get enough readers?):
    All commands include the standard output information and do not exclude any of the standard info (File path, size, create date and time). /b parameters makes the dir command ignore all that, displaying only the file name and its extension (if applicable).

    Take a look at the following example to understand better:

    C:\>cd "%temp%"
    C:\DOCUME~1\User\LOCALS~1\Temp>dir
    Volume in drive C is SYSTEM
    Volume Serial Number is 3032-CEE5
    Directory of C:\DOCUME~1\User\LOCALS~1\Temp
    11/13/2006 10:27 AM <DIR> .
    11/13/2006 10:27 AM <DIR> ..
    11/13/2006 10:19 AM 16,384 C6.tmp
    02/01/2002 04:38 PM 52,413 rwutil.chm
    11/13/2006 10:19 AM <DIR> VBE
    11/13/2006 07:30 AM 512 ~DF5A3B.tmp
    11/13/2006 10:19 AM 49,152 ~DF6B83.tmp
    11/13/2006 10:19 AM 32,768 ~DF7B21.tmp
    11/13/2006 10:19 AM 32,768 ~DF80A5.tmp
    11/13/2006 10:22 AM 27,533 ~WRD3285.doc
    7 File(s) 211,530 bytes
    3 Dir(s) 14,121,275,392 bytes free

    C:\DOCUME~1\User\LOCALS~1\Temp>dir /b
    C6.tmp
    rwutil.chm
    VBE
    ~DF5A3B.tmp
    ~DF6B83.tmp
    ~DF7B21.tmp
    ~DF80A5.tmp
    ~WRD3285.doc

    You could also download and use one of these 2 excellent freewares to do the listing of directories in a much easier way:

    LS-File List Generator

    Karen's Directory Printer


    ~TL

    And one more time, thank you sincerely, for your kind patience with my noob ignorance and all help!

    P.S. And thank you yet for your good humour! In some way that also always helps making a newcomer feel more "at ease"...
    You are quite welcome!!

    You don't seem to be ignorant since you are trying to learn...staying a 'noob' on the same topic for too long, however would be another story.
    Last edited by TurcoLoco; 11-13-2006 at 02:12 PM.

  9. #9
    Join Date
    Nov 2006
    Posts
    3
    Thank you again, TurcoLoco, for the further explanation.

    Speaking of which, at this stage I can only count my own self in as a reader candidate to that sticky on XP command line in your plans, all of a sudden certainly would come as interesting to go thru such a read, also since, yes, mostly what there seems to be around is random collections of listings of commands casually put together, yet lacking any basic background info, which leaves any noob on the subject not too confident of what to do, as well as of what NOT to do, coming to "playing around" with the command prompt, as cauzomb also well pointed out in your poll thread, thus yes, "warnings on side effects and how to avoid them should be noted", most definitely yes too. Anyway best wishes to your project, and as well thank you already for it, as certainly I myself will be one "benefitting" from it.

    And thank you yet also for both those suggestions of programs for making the listing of directories, I shall give it a try with those too, thanks. (Now here's one topic I'm definitely becoming an expert at: thanking you. )
    Last edited by DeLuk; 11-17-2006 at 09:13 AM.

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

    Thumbs up

    You are quite welcome DeLuk. I appreciate all the kind words and support.
    I will do my best to create a noteworthy sticky on the topic but it will be a time consuming project, for that reason, I am thinking about breaking it into separate stickies. For example, Command-Line for Beginners, another for Intermediate and another for Advanced users, etc. That might make more sense....

    I will get working on this when I plan it out first and of course, as time permits.

    ~TL

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
  •