Is there a way to make this script run for every file in a directory. File names are random. I tried *.txt but no luck.
=================================================================
for /f "tokens=2*" %%a in ('findstr /c:"File(s)" "THEFILE.txt"') do (
for /f "tokens=2 delims=\" %%c in ("%%b") do -
Echo %%b
) >> THEFILE.txt
=================================================================
loop a script for multiple files
Moderator: DosItHelp
Re: loop a script for multiple files
You try writing to the same file where you're currently reading it's contents? Not a good idea.
BTW: You should enclose code in Code-Tags.
Post an example of the files content (also enclosed in Code-Tags) and explain what you're trying to do.
Regards
aGerman
BTW: You should enclose code in Code-Tags.
Post an example of the files content (also enclosed in Code-Tags) and explain what you're trying to do.
Regards
aGerman
-
- Posts: 10
- Joined: 08 Mar 2011 08:54
Re: loop a script for multiple files
A sample file would look like this:
so i need this to be at the bottom
the script that selects the values i need and appends it to the end of the file looks like this:
I just need to loop it so it does this to all my files in the directory. In the end all text files will have similar results at the bottom.
Any ideas?
Code: Select all
Directory of Y:\Tom\Program Integration
15/09/2010 06:44 AM 2,523,556 GF (1).avi
15/09/2010 06:45 AM 58,323,282 GF (10).avi
15/09/2010 06:45 AM 34,318,466 GF (11).avi
15/09/2010 06:45 AM 993,988 GF (12).avi
15/09/2010 06:45 AM 17,037,976 GF (13).avi
15/09/2010 06:45 AM 668,494 GF (14).avi
15/09/2010 06:45 AM 33,422,756 GF (15).avi
15/09/2010 06:45 AM 21,128,992 GF (16).avi
15/09/2010 06:45 AM 23,537,194 GF (17).avi
15/09/2010 06:45 AM 20,266,966 GF (18).avi
15/09/2010 06:46 AM 28,177,226 GF (19).avi
15/09/2010 06:44 AM 19,919,346 GF (2).avi
15/09/2010 06:44 AM 18,056,900 GF (3).avi
15/09/2010 06:44 AM 2,690,740 GF (4).avi
15/09/2010 06:44 AM 39,466,326 GF (5).avi
15/09/2010 06:44 AM 47,864,220 GF (6).avi
15/09/2010 06:45 AM 32,951,816 GF (7).avi
15/09/2010 06:45 AM 18,330,400 GF (8).avi
15/09/2010 06:45 AM 39,266,124 GF (9).avi
19 File(s) 458,944,768 bytes
Directory of Y:\Tom\Program Integration\KNOWLEDGE MGMT\
11/08/2010 09:02 AM 28,177,226 (FR).avi
11/08/2010 09:02 AM 20,185,404 Labels (FR) .avi
09/08/2010 12:18 PM 39,266,124 Labels .avi
3 File(s) 28,198,284 bytes
so i need this to be at the bottom
Code: Select all
28,198,284 bytes
458,944,768 bytes
the script that selects the values i need and appends it to the end of the file looks like this:
Code: Select all
for /f "tokens=2*" %%a in ('findstr /c:"File(s)" "THEFILE.txt"') do (
for /f "tokens=2 delims=\" %%c in ("%%b") do -
Echo %%b
) >> THEFILE.txt
I just need to loop it so it does this to all my files in the directory. In the end all text files will have similar results at the bottom.
Any ideas?
Re: loop a script for multiple files
Try it this way:
Regards
aGerman
Code: Select all
@echo off &setlocal
(
for /f "tokens=2*" %%a in ('findstr /c:"File(s)" "THEFILE.txt"') do echo %%b
)>"%temp%\tmpfile.txt"
move "%temp%\tmpfile.txt" "THEFILE.txt"
Regards
aGerman
-
- Posts: 10
- Joined: 08 Mar 2011 08:54
Re: loop a script for multiple files
Not quite. I have multiple files in the same directory and need it so the script runs for each file separately. The trick is to read the file, grab the desired string or strings, append it to the bottom of that same file, then move on to the next txt file. So a loop would be required.
This does what i need but as you can see i have to specify the file name every time.
This does what i need but as you can see i have to specify the file name every time.
Code: Select all
for /f "tokens=2*" %%a in ('findstr /c:"File(s)" "THEFILE.txt"') do (
for /f "tokens=2 delims=\" %%c in ("%%b") do -
Echo %%b
) >> THEFILE.txt
Re: loop a script for multiple files
Hmm, this way?
Regards
aGerman
Code: Select all
@echo off &setlocal
for %%a in (*.txt) do call :proc "%%~a"
del "%temp%\tmpfile.txt"
goto :eof
:proc
(
for /f "tokens=2*" %%a in ('findstr /c:"File(s)" "%~1"') do echo %%b
)>"%temp%\tmpfile.txt"
type "%temp%\tmpfile.txt">>"%~1"
Regards
aGerman
-
- Posts: 10
- Joined: 08 Mar 2011 08:54
Re: loop a script for multiple files
that was simpler than i thought it would be
Thanks a lot aGerman! You're the best
Thanks a lot aGerman! You're the best