finding a text file and replacing it
Moderator: DosItHelp
finding a text file and replacing it
Hi guys,
I've been trying to make a batch file which searches for 2 files (gamemenu.res & browse.vdf) and then replace them with my own version of the files, but since searching the whole system every time will be eating too much resources, it thought it would be better to make a list of the locations (C:\some-folders\...\, D:\some-folders\..., E:\some-folders\...). Could you please help me? I read a lot of tutorials and tried to make my own, but...
Thanks!
I've been trying to make a batch file which searches for 2 files (gamemenu.res & browse.vdf) and then replace them with my own version of the files, but since searching the whole system every time will be eating too much resources, it thought it would be better to make a list of the locations (C:\some-folders\...\, D:\some-folders\..., E:\some-folders\...). Could you please help me? I read a lot of tutorials and tried to make my own, but...
Thanks!
Re: finding a text file and replacing it
Try this: (untested)
c:\mypath is where you have stored your files.
c:\mypath is where you have stored your files.
Code: Select all
@echo off
for %%a in (
"C:\some-folders\"
"D:\some-folders\"
"E:\some-folders\"
) do (
dir /b "%%a\gamemenu.res" >nul 2>&1 && copy /y /b "c:\mypath\gamemenu.res" "%%a"
for %%a in (
"C:\some-folders\"
"D:\some-folders\"
"E:\some-folders\"
) do (
dir /b "%%a\browse.vdf" >nul 2>&1 && copy /y /b "c:\mypath\browse.vdf" "%%a"
Re: finding a text file and replacing it
Hi foxydrive, thanks for trying to help me. But this is the main problem - I don't know the exact location of the files e.g which partion, folders...
Re: finding a text file and replacing it
Who is going to create the list of locations? If you don't want to search the drives then someone has to create the list.
Be more precise in what you want to do...
Be more precise in what you want to do...
Re: finding a text file and replacing it
I was hoping the batch file to scan the partions one time and then to make the list.
Re: finding a text file and replacing it
So you want these two files to be located on your computer, and note where they are? You can do that with the file search function.
Then you can use the batch file above...
Otherwise how do you want to proceed? Please explain what you want the batch file to do.
Then you can use the batch file above...
Otherwise how do you want to proceed? Please explain what you want the batch file to do.
Re: finding a text file and replacing it
Ok. What I want the batch file to do is :
1. Search for the files on the current HDD.
2. Make a list of the locations of those files - doesn't matter where the list is saved (c:\list.txt, d:\1.txt... doesnt matter).
3. Delete the files from those locations.
4. Copy/paste my version (3 + 4 = replacing them).
1. Search for the files on the current HDD.
2. Make a list of the locations of those files - doesn't matter where the list is saved (c:\list.txt, d:\1.txt... doesnt matter).
3. Delete the files from those locations.
4. Copy/paste my version (3 + 4 = replacing them).
-
- Posts: 20
- Joined: 21 Dec 2012 13:36
- Location: United States
Re: finding a text file and replacing it
Here is a script that will scan all the available HDD partitions and write out the matching files to a text file. This will handle steps 1 and 2.
Search Script (Steps 1 & 2):
Replace Script (Steps 3 & 4):
Remove the /l option from the xcopy commands when you want to actually commit to the changes. The /l option causes it to only preview what it would copy and not actually copy the files.
Search Script (Steps 1 & 2):
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "xOutput=C:\Output.txt"
>%xOutput% ( <nul set /p "=" )
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
pushd "%%~D:\" 2>nul
if !ErrorLevel! EQU 0 (
for /f "delims=" %%F in ('dir /a:-d /b /s gamemenu.res browse.vdf') do echo.%%~fF>>%xOutput%
)
popd
)
endlocal
pause
Replace Script (Steps 3 & 4):
Code: Select all
@echo off
setlocal
for /f "usebackq delims=" %%L in ("C:\Output.txt") do (
if "%%~nxL"=="gamemenu.res" xcopy "C:\Temp\gamemenu.res" "%%~fL" /l /r /y
if "%%~nxL"=="browse.vdf" xcopy "C:\Temp\browse.vdf" "%%~fL" /l /r /y
)
endlocal
pause
Remove the /l option from the xcopy commands when you want to actually commit to the changes. The /l option causes it to only preview what it would copy and not actually copy the files.
Re: finding a text file and replacing it
DigitalSnow wrote: if "%%~nxL"=="gamemenu.res" xcopy "C:\Temp\gamemenu.res" "%%~fL" /l /r /y
if "%%~nxL"=="browse.vdf" xcopy "C:\Temp\browse.vdf" "%%~fL" /l /r /y
You should include the /i ignore case switch in the if command as the files may have any capitalisation.
Re: finding a text file and replacing it
Hi DigitalShadow and foxidrive. Thanks for the effort to try to help me. I appreciate it!
I've made a batch file with the first code and ran it - it made a file named "Output.txt", but it was empty - and the cmd window showed "No files found" which is impossible because I have at least 3 files named "GameMenu.res".
I've made a batch file with the first code and ran it - it made a file named "Output.txt", but it was empty - and the cmd window showed "No files found" which is impossible because I have at least 3 files named "GameMenu.res".
Re: finding a text file and replacing it
Try this version: it will probably say no files found several times as it tests all drives.
Code: Select all
@echo off
set "xOutput=C:\Output.txt"
del "%xOutput%" 2>nul
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%D:\ dir /a:-d /b /s %%D:\gamemenu.res %%D:\browse.vdf >>"%xOutput%"
)
pause
Re: finding a text file and replacing it
Thank you both of you. Works like a charm.
Happy Holidays and Best Wishes!
Happy Holidays and Best Wishes!