Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I want to write a batch program to concatenate the number of files in Folder A (The number of files in Folder A may vary)The file 1 looks like this:
Name Addr State Country
A B NJ US
C D CA USand File2 is
Name Addr State Country
E F NJ US
G H CA USThe desired Output file should look like
Name Addr State Country
A B NJ US
C D CA US
E F NJ US
G H CA USI am new to batch programming Please need help with this.
I understand copy command can be used to do this but the file name is
200807test.txt thenother file name will be 200809test.txt i.e. yyyymmtest.txt
Folder A may contain two files today but tommorow it may contain 3 or more files help me with this .
The approach I am following is firstcalculate the number of files in the folder:
echo off
set count=0
CD%1FOR %%i in (*%2) do set /A count+=1
cd ..
echo %count%
then I want to strip off the first line of each and then concatenate.the code for stripping the header is :
for /f "tokens=* skip=1" %%A in (%1) do ( echo %%A >> newfile-firstline-deleted.txt )
this works for one file I want to make it work for all the files in the folder as %1 would be the common text for the file name
can you please help me with this
Thanks In Advance

Hi ksuchetan
Will something like this help if all the Headers are the same
@echo off
echo Name Addr State Country>concat.txt
for /f "tokens=*" %%a in ('type 2008??test.txt') do (
if not "%%a"=="Name Addr State Country" echo %%a>>concat.txt
)

If I have to pass the file name as parameter that is %1 which will have value test.txt and then what will be the value as i want to parametrise this batch so that it will work for group of files with similar name
('type 2008??test.txt')eg: can i give this as ('type *%1')
but this didnot work
Please guide.
Thanks In Advance

The header of the file is very long so when i use this code: it strips correctly for the first file and the next file's header is appended to the last row of the previous file. please find the o\p please guide.
code:
@echo off
if exist "newfile-firstline-deleted.txt" del "newfile-firstline-deleted.txt"
for /f "tokens=* skip=1" %%A in ('type ??%1') do ( echo %%A >> newfile-firstline-deleted.txt )
o\p looks like
A B NJ US
C D CA USName Addr State Country
E F NJ US
G H CA USbut the
Thanks In Advance

@echo off
setLocal EnableDelayedExpansion> newfile echo Name Addr State Country
for /f "tokens=* delims= " %%t in ('dir/b/a-d *.txt') do (
for /f "tokens=* skip=1 delims= " %%a in (%%t) do (
if not "%%a"=="" echo %%a >> newfile
)
)
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |