Question Locked

Help with DOS

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can someone help me what could possibly be wrong with following script.

-------------------------------
cd %1

cd > C:\TEMPFILE.TXT

FindStr "HSP" C:\TEMPFILE.TXT > C:\TEMPFILE.TXT

FOR /F "delims=" %%a in (C:\TEMPFILE.TXT) do set HSPFlag=%%a

del C:\TEMPFILE.TXT

if NOT %HSPFlag%=="" (dir >> C:\TEMPFILE.TXT)

if EXIST C:\DestinationFolder\NUL && EXIST C:\TEMPFILE.TXT (move %1 "C:\DestinationFolder")

del C:\TEMPFILE.TXT
---------------------------------

In Windows Explorer Context Menu, I have added a command "Reviewed" by making changes in registry. The command will call a batch file which will have above script.

Here is what I am trying to achieve. When a person right clicks on a folder and chooses "Reviewed" from the context menu, the selected folder should move to "DestinationFolder" if selected folder's path contains "HSP"

Above script is not working most likely because of some error in IF statements.

Any help would be greatly appreciated.

8 replies

by ahmad

unfortunately that is not an option at this moment.

by dumphrey

cd > C:\TEMPFILE.TXT

why are you trying to redirect a change directory?

May want to repost with a better title, Help with DOS Script or Help with Win Batch File for example.

by bizzo

I'll explain the problems first to make the script easier to see the changes:

FindStr "HSP" C:\TEMPFILE.TXT > C:\TEMPFILE.TXT
Will overwrite the file you're trying to check

You need to unset the HSPFlag variable, as it might already be there.

if NOT %HSPFlag%=="" (dir >> C:\TEMPFILE.TXT)
Doesn't need brackets

if EXIST C:\DestinationFolder\NUL && EXIST C:\TEMPFILE.TXT (move %1 "C:\DestinationFolder")
No brackets and no &&, and you cannot move a directory you've already cd'd to.

I think the following will do what you need it to do:

---------------
cd %1

cd > C:\TEMPFILE.TXT

FindStr "HSP" C:\TEMPFILE.TXT > C:\TEMPFILE2.TXT
set HSPFlag=
FOR /F "delims=" %%a in (C:\TEMPFILE2.TXT) do set HSPFlag=%%a

del C:\TEMPFILE.TXT
del C:\TEMPFILE2.TXT

if NOT "%HSPFlag%"=="" dir >> C:\TEMPFILE.TXT

cd ..
if EXIST C:\DestinationFolder if EXIST C:\TEMPFILE.TXT move %1 "C:\DestinationFolder"

del C:\TEMPFILE.TXT
--------------------------------

Edit: You may also have problems with the %1 and spaces in the folder names, maybe you should surround %1 with "".

by ahmad

> FindStr "HSP" C:\TEMPFILE.TXT > C:\TEMPFILE.TXT
>Will overwrite the file you're trying to check

That's exactly where the problem was. I modified that part and also the && and it worked.

Thanks a lot :)

by churdoo

Nice post, Bizzo. Clearly you should get thumbs for that one.

This discussion is closed to new replies.