Request help building a BAT file to read multiple folders, check for a flag, delete a file and then copy a file. Essentially want to replace a file in multiple folders once.
The folders are user’s profiles in a server. I would like to have a txt file as a flag, if exists do nothing. If it doesn’t exists replace file1 with file2
The folder is: C:\ Documents and Settings
Request a Bat file
Moderator: DosItHelp
Re: Request a Bat file
Your requirements are unclear to me.
You should provide a clearer picture of your directory structure - which folders under "c:\Documents and Settings" are you interested in
Also, for a given folder - What should the before image look like, and what should the after image look like
I don't understand what you mean by replace - Do you replace the contents of file1 with the contents of file2 but preserve file1 name, or do you delete file1 and copy in file2
Is the flag file file1 or file2, or is it a 3rd file
If it is a 3rd file, what process creates or deletes it, and when
Dave Benham
You should provide a clearer picture of your directory structure - which folders under "c:\Documents and Settings" are you interested in

Also, for a given folder - What should the before image look like, and what should the after image look like




Dave Benham
Re: Request a Bat file
Thanks Dave.
In a nutshell, here is what I need to accomplish, all user’s profile have a file in C:\Documents and Settings\%username%\Application Data\Sun\Java\Deployment\deployment.properties. I need to parse all profiles and replace the deployment.properties file with a customized file. The flag file was to check if the deployment.properties file was already replaced and skip.
Any help will be greatly appreciated
In a nutshell, here is what I need to accomplish, all user’s profile have a file in C:\Documents and Settings\%username%\Application Data\Sun\Java\Deployment\deployment.properties. I need to parse all profiles and replace the deployment.properties file with a customized file. The flag file was to check if the deployment.properties file was already replaced and skip.
Any help will be greatly appreciated
Re: Request a Bat file
The customized file will still have the same name as the original, just different content - correct
Is it possible to include the flag inside the customized file
I'm thinking of some line of text that is treated as a comment that does not interfere with the functionality of the file. If the current file is missing the flag line, then we know it needs to be replaced. If it is present then we leave it alone.
Something like this:
Dave Benham

Is it possible to include the flag inside the customized file

Something like this:
Code: Select all
@echo off
setlocal disableDelayedExpansion
set "replacement=CustomizedFile"
set "original=Application Data\Sun\Java\Deployment\deployment.properties"
set "flag=;This file has been updated to version xxx"
for /d %%D in ("C:\Documents and Settings\*") do (
findstr /x /c:"%flag%" "%%D\%original%" >nul || copy /y "%replacement%" "%%D\%original%"
)
Dave Benham
Re: Request a Bat file
Thanks Dave,
It seems to working but it is not leaving the file alone even though the flag line is in the file. It keeps overriding the file.
It seems to working but it is not leaving the file alone even though the flag line is in the file. It keeps overriding the file.
Re: Request a Bat file
Then its not workingTeam710 wrote:It seems to working but it is not leaving the file alone even though the flag line is in the file. It keeps overriding the file.

It should work.

Have you verified that the flag text in the batch script exactly matches the flag text that is in the actual customized file

Dave Benham