Basically, I have a text file with one line of text SetNumber=01
in 5 folders
C:\Documents and Settings\User\Desktop\Test\test.txt
C:\Folder\Test\test.txt
C:\Test\test.txt
etc.
I need to change this SetNumber=01
to different numbers monthly, for instance SetNumber=01
to SetNumber=02
, in all these folders, and would like to run a batch file that would copy and replace this line of text from
C:\Documents and Settings\User\Desktop\Test\test.txt
into
C:Folder\Test\test.txt.
etc.
Any help would be greatly appreciated!!
OK, here we go. This copies the file C:\\Documents and Settings\\User\\Desktop\\Test\\test.txt
to all ..\\test\\test.txt
files on the current volume (they were erased ). Remove the echo
command, if the output is OK:
@echo off&setlocal enabledelayedexpansion
set "sourcefile=C:\Documents and Settings\User\Desktop\Test\test.txt"
for /f "delims=" %%i in ('dir /s /b /a-d \test.txt') do (
set "fpath=%%~fi"
if "!fpath:*test\test.txt=!"=="" if not "%sourcefile%"=="%%~fi" (
echo copy "%sourcefile%" "%%~fi"
)
)
The Batch file below change all files named test.txt in any folder in the disk by inserting this line "SetNumber=%1":
@echo off
for /R \ %%a in (test.txt) do echo SetNumber=%1> "%%a"
For example, if previous Batch file is called SetNumber.bat, you may change all the files to SetNumber=02 with this command:
setnumber=02
Antonio
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.