AT005 Topic Starter
Posts: 13
|
 |
« 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.jpgLets 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
|
|
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« 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
Thanked: 117 Posts: 3,608
Experience: Experienced OS: Windows XP

Roar.
|
 |
« 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? He's playing a game called IRL. Great graphics, *censored* gameplay.
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« Reply #4 on: November 26, 2009, 03:05:06 PM » |
|
I get error message ''%%a was unexpected at this time"
|
|
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« Reply #6 on: November 26, 2009, 03:12:50 PM » |
|
command prompt
start menu / run / ''cmd''
|
|
|
|
|
BatchFileBasics
Thanked: 18 Posts: 387
|
 |
« 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
Posts: 13
|
 |
« 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.
|
|
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« 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...
|
|
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« Reply #12 on: November 26, 2009, 05:17:33 PM » |
|
I have done this (been in correct folder) but nothing happens.
|
|
|
|
|
gh0std0g74
Thanked: 37 Posts: 590
|
 |
« 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
Posts: 13
|
 |
« 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...
|
|
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« Reply #16 on: November 28, 2009, 09:26:14 AM » |
|
hello?
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« Reply #17 on: November 29, 2009, 04:35:43 AM » |
|
I tried with: @echo off for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%binstead of @echo off for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b pauseBut even this doesn't do anything. 
|
|
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« Reply #19 on: November 29, 2009, 08:44:38 AM » |
|
You are doing something wrong. We do not know what, since you don't give enough information. I have tried to use the both codes - of course NOT at the same time. I have pasted them to notepad, each time i saved them as .bat. Firstly used second code but since it doesn't work, I used first one but doesn't work too - two .doc files are still not created. What I wish to have in .doc files is described in my first and second post.
|
|
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« Reply #21 on: November 29, 2009, 08:52:06 AM » |
|
If you meant this: @echo off for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b > filename.doc pauseIt does give me the .doc file but just one instead of two and with terrible results inside - completely different from what I was asking 
|
|
|
|
|
|
|
AT005 Topic Starter
Posts: 13
|
 |
« Reply #23 on: December 04, 2009, 01:30:47 PM » |
|
Why nobody wants to tell me what should I do, in my situation, described in first and third post? 
|
|
|
|
|