Batch script to edit file contents then copy to new folder.

February 13, 2018 at 13:17:00
Specs: Windows 7
Hi All
Looking for some assistance. Very new to this and wondering where I am going wrong.
I am looking at editing out specific lines of text from a file then copying it to a new folder.

The content of the file is as follows;

TW16 930.50
3C1H 1522
4C2 22
R10090045 331 0.600 2.3
R10090045 83 4.800 2.3
R10090035 154 0.600 1.7
R10140035 1 0.300 4.2
R10140035 1 0.900 4.2
R10140035 1 2.100 4.2

I am using findstr to remove the lines containing R10140035 which works fine on its own but I also want to move/copy the file to a new folder.
I can do this all separately which is fine but unable to do it all at once efficiently. I have been playing around with the FOR command but don't believe I am getting the syntax correct.
Tried separators and have not had much luck. The closest I have come is a new blank file in the copy to directory.

The basic script I have gone back to is the following;

@echo off
SET "DESTPATH=C:\export\output\"

set /P JOBNO=Please enter the job number?


echo Exporting Files
findstr /v /c:"R10140035" %EXPORTPATH%\ >
copy /Y "%EXPORTPATH%\" "" > nul
del /q %EXPORTPATH%\*.ftr
for /d %%x in (%EXPORTPATH%\*.ftr) do @rd /s /q "%%x"

) ELSE (

echo missing.
echo Please try and re-export the file.


Any suggestions welcome!

See More: Batch script to edit file contents then copy to new folder.

Reply ↓  Report •

February 13, 2018 at 20:31:30
I think I'm missing something, but here's this:
findstr /v /c:"R10140035" %EXPORTPATH%\ >
copy /Y "%EXPORTPATH%\" "" > nul

findstr /v /c:"R10140035" %EXPORTPATH%\ >""

Still not sure if you want to MOVE or COPY. For 'move' just add a delete.

Reply ↓  Report •

February 14, 2018 at 12:26:33
Thanks, that's great!
For some reason it never really dawned on me that copy wasn't required.

Reply ↓  Report •

February 15, 2018 at 14:36:13
Would there be a way to search and remove the string in all files in the specified folder using a FOR command?
I'm a little confused with setting the required parameters.

Reply ↓  Report •

Related Solutions

February 15, 2018 at 21:41:50
for %%a in (%exportpath%\*.ftr) do (
findstr /v /c:"R10140035" %%a >"%DESTPATH%\%%a"

not sure, not tried. be sure to backup %destpath% since the output IS destructive as written.

message edited by nbrane

Reply ↓  Report •

Ask Question