Question

Locked

Help with DOS

By ahmad ·
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.

This conversation is currently closed to new comments.

8 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Cygwin for the win!

by jerang@ In reply to Help with DOS

If you are more fimilar with Linux, you can install cygwin (http://www.cygwin.com/) It will "translate" DOS to Linux commands.

Collapse -

Re: Cygwin for the win!

by ahmad In reply to Cygwin for the win!

unfortunately that is not an option at this moment.

Collapse -

A few notes

by Dumphrey In reply to Help with DOS

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.

Collapse -

MS-DOS/MSDOS scrip lessons here.... :)

http://www.allenware.com/icsw/icswidx.htm

Please post back if you have any more problems or questions.

Collapse -

A couple of issues

by Bizzo In reply to Help with DOS

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 "".

Collapse -

Re: A couple of issues - Problem solved

by ahmad In reply to A couple of issues

> 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 :)

Collapse -

Nice post, Biz

by Churdoo In reply to A couple of issues

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

Back to Windows Forum
8 total posts (Page 1 of 1)  

Related Discussions

Related Forums