Same instruction in all subfolders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
assurdo
Posts: 2
Joined: 22 Sep 2014 07:13

Same instruction in all subfolders

#1 Post by assurdo » 12 Dec 2016 08:09

Good morning, this is my request, if you can help me:

I have some folders (A, B, C..) and every folder has some subfolders (the subfolders of folder A will be A1, A2, A3..). Every subfolder has some .txt files.

My aim is, through a batch file and I think through a for cycle,
to create, in every subfolder, a single.txt file that will be the the copy of all txt in that folder

Something like:
for (A1, .. A3, B1,...,B3,C1,...)
copy *txt single.txt


Thank you.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Same instruction in all subfolders

#2 Post by aGerman » 12 Dec 2016 11:53

Something like that may work for you:

Code: Select all

@echo off &setlocal
for %%i in ("A" "B" "C") do (
  for /d %%j in ("%%~i\*") do (
    copy "%%~j\*.txt" "%%~j\single.txt"
  )
)

Steffen

Post Reply