Link to home
Start Free TrialLog in
Avatar of Vicki05
Vicki05Flag for United States of America

asked on

Help with a batch file

Can Someone please help.

1. I need to to verify if the folder exists  in C:\Program files (x86) folder.
2. then remove the read only permissions.
3. rename the folder from A to B.
4. Copy files and folder from CD to replace the folder.
5. Remove read only permissions to the folder and its contents after copying.

Thanks,
Vicki
Avatar of oBdA
oBdA

Will the script be on the CD as well? If so, the CD drive will be %~d0, so Source could be defined like this:
set Source=%~d0\Acme
@echo off
setlocal enabledelayedexpansion
set Source=D:\Acme
set Target=C:\Program Files (x86)\Acme

REM The next line sets the following DateTime variables: DT_Day, DT_DayOfWeek, DT_Hour, DT_Minute, DT_Month, DT_Quarter, DT_Second, DT_WeekInMonth, DT_Year
for /f "delims=" %%a in ('wmic.exe Path Win32_LocalTime GET * /value') do (for /f "delims=" %%b in ("%%a") do set DT_%%b)
for %%a in (DT_Month DT_Day DT_Hour DT_Minute DT_Second) do (if !%%a! LSS 10 set %%a=0!%%a!)
set Timestamp=%DT_Year%%DT_Month%%DT_Day%_%DT_Hour%%DT_Minute%%DT_Second%

if exist "%Target%" (
	for %%a in ("%Target%") do set TargetNewName=%%~nxa_%TimeStamp%
	attrib.exe -R "%Target%" /s /d
	ren "%Target%" "!TargetNewName!"
	echo Renamed "%Target%" to "!TargetNewName!"
)
robocopy.exe "%Source%" "%Target%" /e /r:0 /a-:R

Open in new window

This should determine the CD drive automatically based on the source folder:
@echo off
setlocal enabledelayedexpansion
set Source=Acme
set Target=C:\Program Files (x86)\Acme

set /a CDCount = 0
for /f "delims=" %%a in ('wmic.exe logicaldisk WHERE DriveType^=5 GET Caption /value') do (for /f "tokens=2 delims==" %%b in ("%%a") do set /a CDCount+=1&set CD[!CDCount!]=%%b)
if %CDCount%==0 (
	echo Error: could not find a CD drive.
	pause
	exit /b 1
)
for /l %%i in (1, 1, %CDCount%) do (
	echo Testing for "!CD[%%i]!\%Source%" ...
	if exist "!CD[%%i]!\%Source%" (
		set Source=!CD[%%i]!\%Source%
		goto FoundSource
	)
)
echo Error: could not find source folder "%Source%" on any CD.
pause
exit /b 1

:FoundSource
echo Found source: "%Source%"

REM The next line sets the following DateTime variables: DT_Day, DT_DayOfWeek, DT_Hour, DT_Minute, DT_Month, DT_Quarter, DT_Second, DT_WeekInMonth, DT_Year
for /f "delims=" %%a in ('wmic.exe Path Win32_LocalTime GET * /value') do (for /f "delims=" %%b in ("%%a") do set DT_%%b)
for %%a in (DT_Month DT_Day DT_Hour DT_Minute DT_Second) do (if !%%a! LSS 10 set %%a=0!%%a!)
set Timestamp=%DT_Year%%DT_Month%%DT_Day%_%DT_Hour%%DT_Minute%%DT_Second%

if exist "%Target%" (
	for %%a in ("%Target%") do set TargetNewName=%%~nxa_%TimeStamp%
	attrib.exe -R "%Target%" /s /d
	ren "%Target%" "!TargetNewName!"
	echo Renamed "%Target%" to "!TargetNewName!"
)
robocopy.exe "%Source%" "%Target%" /e /r:0 /a-:R

Open in new window

Avatar of Vicki05

ASKER

Is this a Dos batch File? yes the batch file will be on the CD as well.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vicki05

ASKER

Thanks, I will give it a go.
Avatar of Vicki05

ASKER

I ran the batch file, if the path is not there, it does not skip it. It creates the path and continues. I want it to skip that section. I have to install on Windows XP 32 bit and Windows 7 64 bit. So I need to verify if the path is there then to execute the next steps. If it is not there, to skip and go to next.

1. I need to to verify if the folder exists  in C:\Program files (x86) folder.

If folder exists then
 2. then remove the read only permissions.
 3. rename the folder from A to B.
 4. Copy files and folder (x86) from CD to replace the folder.
 5. Remove read only permissions to the folder and its contents after copying.

If folder does not exist then

1. I need to to verify if the folder exists  in C:\Program files folder.

 2. then remove the read only permissions.
 3. rename the folder from A to B.
 4. Copy files and folder (x64) from CD to replace the folder.
 5. Remove read only permissions to the folder and its contents after copying.

64 bit and 32 bit files are different.
I think something's wrong in your description.
The "Program Files (x86)" folder will only exist on x64 Windows, and contain 32 bit software.
The "Program Files" folder will exist both on x86 and x64 Windows, and contain 32 bit software on a 32bit OS (XP) and 64bit software on a 64bit OS (Win7).
So, on XP/x86 OS, the situation is obvious, source x86 and target "Program Files".
On WIn7/64bit OS, the situation should be just as obvious if you say "64 bit and 32 bit files are different.", namely source x64 and target "Program Files".
So when do you see the "Program Files (x86)" folder in use at all? Could it be that the 32bit version of the software was installed on some WIn7 machines?
Avatar of Vicki05

ASKER

I have 2 versions of system that I need to load the files. I need to verify if the 32 bit OS is installed then install the x32 files. On the 64 bit system I need to install 64 bit folder and files.
I completely aware the part with the difference between x86/x64 OS and their respective sources and targets.
What I don't understand is why (both in your initial question and in https:#a41616653) you need/want to query inside the "Program Files (x86)" folder.
As I pointed out in https:#a41616946, this folder should not be in use at all, because it would mean that the 32bit software was installed on a 64bit OS, which shouldn't be the case, with a dedicated 64bit version existing.
Please clarify.
Avatar of Vicki05

ASKER

The software is designed for a 32 bit system. Now with new 64 bit systems like you said. It gets installed in X86 folder.

So basically if there is C:\program files (x86)\ Test\Hello folder, then install the 32 bit files with the path pointing to C:\Program Files (x86) folder.
If there is C:\program files\ Test\Hello folder, then install the 32 bit files C:\Program Files folder

Both files that need to be installed are configured have different paths assigned to them. So if I can verify that it is a 32 bit OS. I would like to install this specific files. If it s a 64, I need to install in x86 folder.

Does that make any sense?
Nope, sorry. You probably have me more confused than before.
Earlier, you said "64 bit and 32 bit files are different." and "On the 64 bit system I need to install 64 bit folder and files."
In your last comment, you're saying "The software is designed for a 32 bit system. Now with new 64 bit systems like you said. It gets installed in X86 folder." (which is the case for any 32bit software running in Wow64).
These two comments do not fit together.
If you do have a 64bit version of the software, then it should be installed to "C:\Program Files" on a 64bit OS.

To sum it up, there are three possible cases:
1. A 32bit SW on a 32bit OS will be installed to "C:\Program Files".
2. A 32bit SW on a 64bit OS will be installed to "C:\Program Files (x86)".
3. A 64bit SW on a 64bit OS will be installed to "C:\Program Files".

You're saying that you have 64bit SW, so on WIn7, case 3 should apply. Why then (from your last comment) "If it s a 64, I need to install in x86 folder"?
Avatar of Vicki05

ASKER

Thanks this worked. I just moved the Robocopy up before the closed ).
Avatar of Vicki05

ASKER

Hi ObDA,

The batch file does not run from a CD. It does not work on Windows XP either. Please help.