Computing.Net > Forums > Programming > Process all files in a folder

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Process all files in a folder

Reply to Message Icon

Name: ksuchetan
Date: July 15, 2008 at 11:30:45 Pacific
OS: WINXP
CPU/Ram: 2 gb
Comment:

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 US

and File2 is

Name Addr State Country
E F NJ US
G H CA US

The 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 US

I 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 first

calculate the number of files in the folder:

echo off
set count=0
CD%1

FOR %%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



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: July 15, 2008 at 13:58:11 Pacific
Reply:

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
)


0

Response Number 2
Name: ksuchetan
Date: July 15, 2008 at 15:57:25 Pacific
Reply:

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


0

Response Number 3
Name: ksuchetan
Date: July 15, 2008 at 16:07:13 Pacific
Reply:

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 US

but the

Thanks In Advance


0

Response Number 4
Name: Mechanix2Go
Date: July 16, 2008 at 02:40:15 Pacific
Reply:

@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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Process all files in a folder

zip all the .csv files in a folder www.computing.net/answers/programming/zip-all-the-csv-files-in-a-folder/16724.html

Process all files in folder www.computing.net/answers/programming/process-all-files-in-folder-/19757.html

Batch program to process all files in folder www.computing.net/answers/programming/batch-program-to-process-all-files-in-folder/19798.html