Strange behavior with global variable

August 15, 2010 at 08:24:30
Specs: Windows 7 / 64 bit, Q9550 / 4 Gig
Hi there,

I've made a batch script which has to copy a txt to ThisFolder in AppData and then to make some actions in there. It starts like this:

@echo off

copy "ThisFile.txt" "%appdata%\ThisFolder\"

cd "%appdata%\ThisFolder\"
....

Script works fine when is executed from c: but if It is executed it from another hard drive it does not work. Actually it makes the actions but in the folder that batch file is located and not in AppData\ThisFolder. As far I can understand does not execute the line:

cd "%appdata%\ThisFolder\"

Your help is mostly appreciated,

Best regards

(Whole script follows)

@echo off

copy "ThisFile.txt" "%appdata%\ThisFolder\"

cd "%appdata%\ThisFolder\"

IF EXIST AnOther.txt. (GOTO CHANGETYPE) ELSE (GOTO CREATEFILE)

:CHANGETYPE
TYPE AnOther.txt > temp.txt

findstr /i /c:"MyString" temp.txt
IF %errorlevel% EQU 0 (GOTO END) ELSE (GOTO COMMOD)

:COMMOD
echo:
echo MyString >> temp.txt

GOTO END

:CREATEFILE
echo MyString > temp.txt

:END

COPY /Y ThisFile.txt AnOther.txt
CMD /U /C Type temp.txt >> AnOther.txt

del temp.txt
del ThisFile.txt

Exit


See More: Strange behavior with global variable

Report •

#1
August 15, 2010 at 08:46:52
rem executed on xp
cd /?


.....
Use the /D switch to change current drive in addition to changing current
directory for a drive.
.....

Simply put:

.....
cd /d "%appdata%\ThisFolder\"


Report •

#2
August 15, 2010 at 09:51:07
Thanks a lot, it works like a charm!



Report •
Related Solutions


Ask Question