Page 1 of 1
Combine files and create a single file
Posted: 03 Jan 2014 14:31
by Danny
Hi,
Below script copies the files to my backup drive with ease, now when all the text files are copied in destination folder i want to combine them and create a single text file while removing the header line the first line in the text file and then delete all the text files and preserve this combined file in the same folder and naming it on date.
Code: Select all
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%DD%-%MM%-%YYYY%"
for /d %%a in ("D:\Depository\picture\%dd%%mm%%yyyy%\data\*") do (
xcopy "%%a\*.tiff" "F:\Repository\%%~nxa\%datestamp%\download\Images\"
xcopy "%%a\*.txt" "F:\Repository\%%~nxa\%datestamp%\download\TEXT\"
)
Re: Combine files and create a single file
Posted: 03 Jan 2014 16:59
by zpimp
to concatenate all text files in a folder in file.txt, and delete after
copy /b *.txt file.txt
del /f /q *.txt
Re: Combine files and create a single file
Posted: 03 Jan 2014 17:59
by foxidrive
Danny wrote:
when all the text files are copied in destination folder i want to combine them and create a single text file while removing the header line the first line in the text file and then delete all the text files and preserve this combined file in the same folder and naming it on date.
xcopy "%%a\*.txt" "F:\Repository\%%~nxa\%datestamp%\download\TEXT\"
Do you mean all the files that are copied by the command above? Are there any other files in the TEXT folder that need to be included in the combinedfile?
Re: Combine files and create a single file
Posted: 04 Jan 2014 00:33
by Danny
foxidrive wrote:Do you mean all the files that are copied by the command above? Are there any other files in the TEXT folder that need to be included in the combinedfile?
Hi,
No, there are no other types of files in the TEXT folder, Only .txt files.
Thanks in advance.
Re: Combine files and create a single file
Posted: 04 Jan 2014 03:04
by foxidrive
foxidrive wrote:Do you mean all the files that are copied by the command above? Are there any other files in the TEXT folder that need to be included in the combinedfile?
Will this folder be empty when the batch file runs?
"F:\Repository\%%~nxa\%datestamp%\download\TEXT\"
Re: Combine files and create a single file
Posted: 04 Jan 2014 06:01
by Danny
Hi,
Yes the folder is empty, infact this "F:\Repository\%%~nxa\%datestamp%\download\TEXT\" creates the TEXT folder if it does not exits and then copies from the source to destination.
Thanks.
Re: Combine files and create a single file
Posted: 04 Jan 2014 06:37
by foxidrive
This replies on the *.txt files being less than 64 K lines long, and if any TAB characters are in the file then they will be replaced with runs of space characters.
It removes the first line of every text file, saving them all in one file.
Code: Select all
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%DD%-%MM%-%YYYY%"
for /d %%a in ("D:\Depository\picture\%dd%%mm%%yyyy%\data\*") do (
xcopy "%%a\*.tiff" "F:\Repository\%%~nxa\%datestamp%\download\Images\"
md "F:\Repository\%%~nxa\%datestamp%\download\TEXT\" 2>nul
for %%b in ("%%a\*.txt") do more +1 "%%b" >>"F:\Repository\%%~nxa\%datestamp%\download\TEXT\%datestamp%.txt"
)
Re: Combine files and create a single file
Posted: 04 Jan 2014 11:13
by Squashman
zpimp wrote:to concatenate all text files in a folder in file.txt, and delete after
copy /b *.txt file.txt
del /f /q *.txt
cyclical copy. It will never end because it will keep trying to copy itself and then of course your code would then delete all your hard work.
Re: Combine files and create a single file
Posted: 04 Jan 2014 21:37
by foxidrive
Squashman wrote:zpimp wrote:to concatenate all text files in a folder in file.txt, and delete after
copy /b *.txt file.txt
del /f /q *.txt
cyclical copy. It will never end because it will keep trying to copy itself and then of course your code would then delete all your hard work.
It will end, but you'll get more than you bargained for in the file - and *then* it will delete everything.