Windows batch looping through subfolders and running a command -


i'm trying have nested loop in windows command prompt go each subfolder in specified folder concatenate text files in there 1 text file. i'm trying use

for /f  in (.) (for %f in (*.dat) type “%f” >> aggregate.txt) 

but not working. me!

i'm not sure if want concatenate .txt or .dat files, should work .dat

(for /r %f in (*.dat) @type "%f")>aggregate.txt 

type help for command line more info on many forms of statement.

it more efficient enclose whole command in parentheses , redirection once instead of doing append redirection each file.

edit - solution refined requirement in comment: 1 aggregate per folder

if needed, first delete existing aggregate.txt files

del /s aggregate.txt 

then following should give desired result

for /r %f in (*.dat) @type "%f" >>"%~dpf\aggregate.txt" 

note if put commands in batch file must double percents before variables. example, %f on command line need %%f in batch file.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -