Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Command Prompt (CMD); Two issues about DIR command  (Read 8179 times)

0 Members and 1 Guest are viewing this topic.

AT005

    Topic Starter


    Rookie

    Command Prompt (CMD); Two issues about DIR command
    « on: November 26, 2009, 02:19:38 PM »
    Hi everyone

    Finally I found some forum with a section for CMD topic and I hope I could find my so long searching answers here. If someone could take a look at my two issues about CMD, I would appreciate it a lot:

    I am using the following command:

    dir /ad /s /b > filename.doc

    but to get what I need, I can change to command to something else (instead of just adding new parameters).

    1. Could I get as the result (text inside file filename.doc) only two parts of each line? What I mean is this:

    I have the line that looks like:

    C:\Main Folder\Subfolder\Subsubfolder\[blabla] example_of_folder_name

    I would like to have this only:

    Subsubfolder\[blabla]

    In each of line (no matter how many hundreds or thousands of lines) only those two parts.

    2. Here is one screenshot that I made:

    http://img.photobucket.com/albums/v309/Andreii/folder1.jpg

    Lets say here are two groups of folders: first group is in the red square, second is in the green square. This is just an example. In the second group I usually have 1000+ folders (and not just 5) but the amount of folders is irrelevant comparing to my second issue.  What I would like to have are two different .doc files - one for first group of folders and one for second group. All of the subfolders, subsubfolders etc (just filenames not as my cmd command above shows) must always be in the .doc lists but in the format of text (some pieces of lines must be cutted) about which I was asking in my first issue.

    Hopefully someone could help.

    Thank you

    Kindest regards

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: Command Prompt (CMD); Two issues about DIR command
    « Reply #1 on: November 26, 2009, 02:23:47 PM »
    Will it always be the same level of folders deep?
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    AT005

      Topic Starter


      Rookie

      Re: Command Prompt (CMD); Two issues about DIR command
      « Reply #2 on: November 26, 2009, 02:46:48 PM »
      Will it always be the same level of folders deep?

      Thank you for reply. Im not exsactly sure what you mean with ''folders deep'' but I can presume that you meant how many folders are before (''above'') subsubfolder. In this example:

      C:\Main Folder\Subfolder\Subsubfolder\[blabla] example_of_folder_name

      There are two folders before.

      If I presumed wrong, please tell me what you meant with ''folders deep''.

      If I presumed correctly then:

      In the second group (green square): yes. Folders will always look like:

      C:\Main Folder\Subfolder\Subsubfolder\[blabla] example_of_folder_name

      So im always interested at ''Subsubfolder\[blabla]'' only.

      In the first group (red square): no. Between ''Subsubfolder'' and ''[blabla]'' are another unlimited amount of folders located. So the path look like this:

      C:\Main Folder\Subfolder\Subsubfolder\Subsubsubfolder\[blabla] example_of_folder_name

      So im always interested at ''Subsubsubfolder\[blabla]'' only.

      I also need to mentoin the following because it might change the answers on the questions that im interested for:

      In the first group (red square) are exsactly 7 subsubfolders - Im talking only about subsubfolders and NOT any other ''depth'' of folders. Those subsubfolders will always be there, always with the same number of them (7) and always with the same names.
      The part of the latest (the most deepest) folder that Im interested for will always be between ''['' and '']'' (i would prefer to have those two symbols written in the .doc file too) BUT i cannot guarantee there will always be a space between '']'' and first next letter (of if is number of even symbol).

      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: Command Prompt (CMD); Two issues about DIR command
      « Reply #3 on: November 26, 2009, 02:54:23 PM »
      Here you go! (And you did assume right :))

      for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      AT005

        Topic Starter


        Rookie

        Re: Command Prompt (CMD); Two issues about DIR command
        « Reply #4 on: November 26, 2009, 03:05:06 PM »
        I get error message ''%%a was unexpected at this time"

        Helpmeh



          Guru

        • Roar.
        • Thanked: 123
          • Yes
          • Yes
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 8
        Re: Command Prompt (CMD); Two issues about DIR command
        « Reply #5 on: November 26, 2009, 03:11:54 PM »
        Are you running it from the command prompt or a batch file?
        Where's MagicSpeed?
        Quote from: 'matt'
        He's playing a game called IRL. Great graphics, *censored* gameplay.

        AT005

          Topic Starter


          Rookie

          Re: Command Prompt (CMD); Two issues about DIR command
          « Reply #6 on: November 26, 2009, 03:12:50 PM »
          command prompt

          start menu / run / ''cmd''

          BatchFileBasics



            Hopeful

            Thanked: 18
            Re: Command Prompt (CMD); Two issues about DIR command
            « Reply #7 on: November 26, 2009, 04:16:24 PM »
            thats the problem, you can't use for loops in the command prompt without a script.
            When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

            AT005

              Topic Starter


              Rookie

              Re: Command Prompt (CMD); Two issues about DIR command
              « Reply #8 on: November 26, 2009, 04:21:37 PM »
              thats the problem, you can't use for loops in the command prompt without a script.

              Thank you for reply. And how do I make this so the command which Helpmeh typed will work? I remember somewhen I have used to read that it needs to be written in notepad and saved as .bat extension but not sure if this is correct. In the folders I have very important files for myself and I will not just ''test'' something because I THINK its correct so I wouldn't damage something or do something wrong. I prefered to ask for proven, correct solution instead of trying the luck.

              Helpmeh



                Guru

              • Roar.
              • Thanked: 123
                • Yes
                • Yes
              • Computer: Specs
              • Experience: Familiar
              • OS: Windows 8
              Re: Command Prompt (CMD); Two issues about DIR command
              « Reply #9 on: November 26, 2009, 04:29:08 PM »
              Yes.
              Just put

              @echo off

              as the first line, then add my code on the next line. Add

              pause

              on the line after my code, and save it as file.bat .
              Where's MagicSpeed?
              Quote from: 'matt'
              He's playing a game called IRL. Great graphics, *censored* gameplay.

              AT005

                Topic Starter


                Rookie

                Re: Command Prompt (CMD); Two issues about DIR command
                « Reply #10 on: November 26, 2009, 04:46:01 PM »
                I got the .bat file now, Im pretty sure its correct. Also the icon got changed from notepad's one to ms-dos' one. Sorry about the question but how do I use this? I don't have much experience with scripting...

                Helpmeh



                  Guru

                • Roar.
                • Thanked: 123
                  • Yes
                  • Yes
                • Computer: Specs
                • Experience: Familiar
                • OS: Windows 8
                Re: Command Prompt (CMD); Two issues about DIR command
                « Reply #11 on: November 26, 2009, 05:13:45 PM »
                I got the .bat file now, Im pretty sure its correct. Also the icon got changed from notepad's one to ms-dos' one. Sorry about the question but how do I use this? I don't have much experience with scripting...
                Just double-click on it. Now that you know what that icon looks like, I want to impress on you never to run/open files you haven't seen before and/or don't know what it does. For all .bat files, you can right-click and select Edit to see the source code. If you don't know what the code does, post it here and we can tell you what it will do.
                Where's MagicSpeed?
                Quote from: 'matt'
                He's playing a game called IRL. Great graphics, *censored* gameplay.

                AT005

                  Topic Starter


                  Rookie

                  Re: Command Prompt (CMD); Two issues about DIR command
                  « Reply #12 on: November 26, 2009, 05:17:33 PM »
                  I have done this (been in correct folder) but nothing happens.

                  gh0std0g74



                    Apprentice

                    Thanked: 37
                    Re: Command Prompt (CMD); Two issues about DIR command
                    « Reply #13 on: November 26, 2009, 05:50:45 PM »
                    Here you go! (And you did assume right :))

                    for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b
                    what if there are more levels deep? can't really have tokens 4,5 right?

                    AT005

                      Topic Starter


                      Rookie

                      Re: Command Prompt (CMD); Two issues about DIR command
                      « Reply #14 on: November 26, 2009, 11:34:56 PM »
                      what if there are more levels deep? can't really have tokens 4,5 right?

                      First group of folders (red square on the screenshot), for one out of two doc files, will always have its own levels depth. Also the second group of folders (green square on the screenshot), for the second doc file, will always have its own levels depth too - both kind of depths will be the same as stated above.

                      Hopefully I can make this .bat file to work. Helpmeh Is it an error in the source code? I typed inside exsactly this:

                      @echo off
                      for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b
                      pause

                      According to the message (some kind of ''press any key to continue'') that im getting, I cannot call this message an Error but still, because of it, im not getting the result (new two files in .doc extension). I think the ''pause'' might be the reason for that...