How to? Append files in multiple subfolders using copy?

Oct 18, 2009
362
17
Is it possible to append text files in different subfolders into a single file using copy without using a detailed looping approach?

Basically, I have this setup:

\2018\Sep
..\01
..\02
(etc ...)

About 20 of the subfolders contain a file with a standard name: PMT_2018-09-DD.txt where DD is the day.

I want to combine those into a single file.

I tried copy /s {pattern} F:\temp\target.txt but that copied the whole directory structure, etc., rather than appending.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,491
90
Albuquerque, NM
prospero.unm.edu
Wow; you may have found an actual use for GLOBAL. Those are rare....

(Remember that you need to change to the top-level directory before using GLOBAL, e.g. with PUSHD.)
 
May 20, 2008
11,520
102
Syracuse, NY, USA
This worked.
Code:
v:\> type 1.txt
1

v:\> type rtt\2.txt
2

v:\> copy /b 1.txt+rtt\2.txt 3.txt
V:\1.txt => V:\3.txt
V:\rtt\2.txt =>> V:\3.txt
     2 files copied

v:\> type 3.txt
1
2

So did this.
Code:
v:\> type 1.txt
1

v:\> type rtt\2.txt
2

v:\> copy /b 1.txt+rtt\2.txt
V:\rtt\2.txt =>> V:\1.txt
     1 file copied

v:\> type 1.txt
1
2
 
May 20, 2008
11,520
102
Syracuse, NY, USA
GLOBAL together with file concatenation should work. Here's a very simple example. It seems that GLOBAL would benefit from an option to process only proper subdirectories (that is, to skip the top, current directory).

Code:
v:\sep> tree /f v:\sep

V:\sep
├──1
│  └  1.log
├──2
│  └  2.log
├──3
│  └  3.log
├──4
│  └  4.log
└──5
   └  5.log

v:\sep> do i=1 to 5 ( dir /m /k %i\%i.log )
2018-11-19  13:30               3  1.log
2018-11-19  13:30               3  2.log
2018-11-19  13:30               3  3.log
2018-11-19  13:30               3  4.log
2018-11-19  13:30               3  5.log

v:\sep> touch /c sep.log & global /iq if %_cwd ne v:\sep copy /b v:\sep\sep.log+*.log v:\sep\sep.log
2018-11-19 13:46:13.668  V:\sep\sep.log
V:\sep\1\1.log =>> V:\sep\sep.log
     1 file copied
V:\sep\2\2.log =>> V:\sep\sep.log
     1 file copied
V:\sep\3\3.log =>> V:\sep\sep.log
     1 file copied
V:\sep\4\4.log =>> V:\sep\sep.log
     1 file copied
V:\sep\5\5.log =>> V:\sep\sep.log
     1 file copied

v:\sep> dir /m /k /h
2018-11-19  13:30         <DIR>    1
2018-11-19  13:30         <DIR>    2
2018-11-19  13:30         <DIR>    3
2018-11-19  13:30         <DIR>    4
2018-11-19  13:30         <DIR>    5
2018-11-19  13:46              15  sep.log
 
May 20, 2008
11,520
102
Syracuse, NY, USA
FWIW,
Code:
do subdir in /a:d * ...
can be made to act like a (1-deep) GLOBAL and you don't have to worry about the top level.
 
May 20, 2008
11,520
102
Syracuse, NY, USA
Yes, but Rick wanted to do it "without using a detailed looping approach ". Even GLOBAL is a "loop" but the missing details can make it hard to use.
 
Oct 18, 2009
362
17
Thanks! If forgot that the "names" of the files to be concatenated can include paths. This works:

copy .\*\PMT_20??-??-??.txt "F:\Temp\All_Pmts.txt"
 
Similar threads
Thread starter Title Forum Replies Date
M Can "append to clipboard when shift is held down" be disabled? Support 1
samintz WAD Copy/append adds a character Support 3
SeoulBigChris Does TC intercept the APPEND command? Support 7
vefatica Append command line to @@key alias? Support 13
vefatica Append something entered to a file? Support 12
MickeyF TCC crashing when copying multiple files (now resolved) Support 6
fpefpe How to? shortcuts and batch files Support 4
C v28 key files Support 2
J ffind does not find files Support 4
C duplicate files in multiple plugin sites Support 9
Dmitry L. Kobyakov Fixed The SETARRAY /R command works incorrectly with cyrillic files Support 2
S How to? Deinstalling TC/reinstating execution of bat files by cmd in Win7 Support 31
vefatica FFIND, temp files? ... not deleted? Support 0
R FUNCTION to count NUMBER of files matching a pattern and specific length/not length Support 4
vefatica Tmp files from in-process pipes not deleted Support 6
vefatica Finding files with alternate data streams? Support 4
rps Multi-column DIR /v not displaying all files. Support 5
D How to skip files in a fileset? Support 6
vefatica PIPEVIEW leaves TMP files Support 18
K "copy /z /w" command not deleting read-only files in destination Support 10
Jesse Heines "Taken" date for JPG and PNG files Support 4
O I cannot use links to .btm files Support 5
C How to? rename files with spaces Support 8
Joe Caverly "Functions" in cmd.exe batch files Support 6
S Batch files Calling Batch Files Support 2
vefatica Find Files/Text dialog: does it work? Support 0
Joe Caverly UNZIPping older .ZIP files Support 3
C Documentation default location for LOG files Support 21
P exit /b in batch files Support 7
P Labels in batch files: TCC vs CMD.exe Support 9
M ANSI is used to show files instead of OEM in version 17 to 19 ! Support 5
C 7Z files on forum? Support 0
x13 Problem listing repository files using DIR http(s)://... Support 8
B Can copy command concatenate multiple mp3 files Support 2
redwdc Copying files with spaces, commas, etc. Support 5
J New lexer for TCC batch files. Support 0
M How to? want to download a file from a website enumarate the links and download the files Support 2
keithg1964 TCC RT Install Files Support 1
P Fixed Rexx .cmd files no longer work in TCC 20 Support 3
thorntonpg Handling files with embedded spaces Support 1
WavSlave Fixed Unable to sort files by description in TCC v19 Support 2
P Files older - exist Support 1
D safe delete files command Support 10
P Copying files in subdirectories Support 9
C WAD VIEW print multiple files - switches fail Support 10
MikeBaas How to? SELECT: exclude files / display prompt Support 2
Phileosophos WAD Can't rename files in subfolders Support 1
nickles WAD del unable to delete files ending in "." Support 18
P Rename files with ampersand in the name Support 1
C Touch command — I Need to touch matching files in another directory. Support 5

Similar threads