Computer Hope
Microsoft => Microsoft DOS => Topic started by: AT005 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
-
Will it always be the same level of folders deep?
-
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).
-
Here you go! (And you did assume right :))
for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b
-
I get error message ''%%a was unexpected at this time"
-
Are you running it from the command prompt or a batch file?
-
command prompt
start menu / run / ''cmd''
-
thats the problem, you can't use for loops in the command prompt without a script.
-
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.
-
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 .
-
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...
-
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.
-
I have done this (been in correct folder) but nothing happens.
-
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?
-
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...
-
thats the problem, you can't use for loops in the command prompt without a script.
That is not so; at the prompt you just use one % sign in the loop variables (instead of two)
S:\Test>for /f "tokens=1,2,3,4,5 delims=\" %a in ('dir /ad /s /b') do @echo %a\%b\%c\%d\%e
S:\Test\Batch\Older\custom-path
S:\Test\Other\Auto-it\
S:\Test\Other\Basic\
S:\Test\Other\beep\
S:\Test\Other\cURL\
S:\Test\Other\FTP\
S:\Test\Other\FUS-Repair\
S:\Test\Other\getmail\
S:\Test\Other\ghacker\
S:\Test\Other\hta\
S:\Test\Other\kix\
S:\Test\Other\Mirakagi\
S:\Test\Other\NATW\
S:\Test\Other\PopClient\
S:\Test\Other\Portable-Ubuntu\
S:\Test\Other\Python\
S:\Test\Other\reg\
S:\Test\Other\Ruby\
S:\Test\Other\textview\
S:\Test\Other\UnxUtils\
S:\Test\Other\virtual disk\
S:\Test\Other\wget_GUI\
S:\Test\Other\winmsg\
S:\Test\Other\winWget\
S:\Test\Other\wmv-avi\
S:\Test\Other\Zerodir\
S:\Test\Other\Auto-it\Auto-it3
S:\Test\Other\Auto-it\Checkbox
S:\Test\Other\Auto-it\MsgBox
S:\Test\Other\Auto-it\Auto-it3
S:\Test\Other\Auto-it\Auto-it3
-
hello?
-
I tried with:
@echo off
for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b
instead of
@echo off
for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b
pause
But even this doesn't do anything. :(
-
You are doing something wrong. We do not know what, since you don't give enough information.
-
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.
-
You left the > filename.doc off the end.
-
If you meant this:
@echo off
for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b > filename.doc
pause
It does give me the .doc file but just one instead of two and with terrible results inside - completely different from what I was asking ???
-
I think you are going to have to learn some batch scripting
-
Why nobody wants to tell me what should I do, in my situation, described in first and third post? :(