Question

  • Creator
    Topic
  • #2150339

    Help with DOS

    Locked

    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.

All Answers

  • Author
    Replies
    • #2923398

      Clarifications

      by ahmad ·

      In reply to Help with DOS

      Clarifications

    • #2923379

      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.

      • #2923366

        Re: Cygwin for the win!

        by ahmad ·

        In reply to Cygwin for the win!

        unfortunately that is not an option at this moment.

    • #2923352

      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.

    • #2923343

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

      by Anonymous ·

      In reply to Help with DOS

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

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

    • #2922603

      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 “”.

      • #2922580

        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 🙂

      • #2908028

        Nice post, Biz

        by churdoo ·

        In reply to A couple of issues

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

Viewing 4 reply threads