Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file help  (Read 10150 times)

0 Members and 1 Guest are viewing this topic.

acidblue

    Topic Starter


    Rookie

    Batch file help
    « on: July 28, 2010, 09:09:11 PM »
    I wrote a batch file to copy jpg images to a directory but it just hangs and doesn't copy anything.
    here is my code:
    Code: [Select]
    @echo off
    xcopy "c:\Documents and Settings\%username%\My Documnets\My Pictures\*.jpg" c:\

    This is on a WINXP box,as far as I can tell this should work but it doesn't.

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: Batch file help
    « Reply #1 on: July 29, 2010, 06:29:46 AM »
    You spelled Documents wrong. You wrote: My Documnets
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    acidblue

      Topic Starter


      Rookie

      Re: Batch file help
      « Reply #2 on: July 29, 2010, 11:22:15 AM »
      DOH!!  :o
      Still doesn't work, something wrong with my version of XCOPY.
      Even doing something simple like;
      Code: [Select]
      xcopy c:\file.jpg c:\file2.jpgdoesn't work, cmd screen just hangs with a blinking cursor

      southpaw63119



        Beginner
      • Thanked: 3
        • Yes
        • Yes
      • Experience: Experienced
      • OS: Linux variant
      Re: Batch file help
      « Reply #3 on: July 29, 2010, 12:25:04 PM »
      You can't see it because you have
      Code: [Select]
      @echo off at the beginning of your batch file, but it should be because you are being prompted whether you are copying a file or a directory.

      Using the following should fix the problem, but you will NOT be prompted when files will be overwritten:
      Code: [Select]
      xcopy [source] [destination] /Y

      Actually this post is probably wrong...but still worth a try.
      I jumped the gun, and didn't actually test the code with @echo off...which when I DID run it with @echo off, the prompt still appeared.
      My apologies.
      « Last Edit: July 29, 2010, 12:41:11 PM by southpaw63119 »
      This is why we can't have nice things.

      acidblue

        Topic Starter


        Rookie

        Re: Batch file help
        « Reply #4 on: July 29, 2010, 01:00:06 PM »
        Still not working.
        Code: [Select]
        @echo off
        xcopy c:\pix.jpg c:\pix2.jpg /Y

        However using 'copy' instead of 'xcopy' works.
        Code: [Select]
        @echo off
        copy c:\pix.jpg c:\pix2.jpg /Y
        Strange  ???

        southpaw63119



          Beginner
        • Thanked: 3
          • Yes
          • Yes
        • Experience: Experienced
        • OS: Linux variant
        Re: Batch file help
        « Reply #5 on: July 29, 2010, 01:03:20 PM »
        That is pretty strange...
        But, on the bright side, it works. :)
        This is why we can't have nice things.

        acidblue

          Topic Starter


          Rookie

          Re: Batch file help
          « Reply #6 on: July 29, 2010, 01:11:08 PM »
          Oh well.  ;D
          Just one more thing what's the switch to copy files recursively??
          In *nix it's -r, would that be /r in winXP??
          Code: [Select]
          copy /R "%userprofile%\my documents\*.jpg" c:\ /Y  ??

          Salmon Trout

          • Guest
          Re: Batch file help
          « Reply #7 on: July 29, 2010, 01:15:35 PM »
          Just one more thing what's the switch to copy files recursively??

          There isn't one for the COPY command. Xcopy has the /s switch.

          To get the help on a Windows command, type the command, a space, a forward slash and a question mark.

          Code: [Select]
          C:>copy /?
          Copies one or more files to another location.

          COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
               [+ source [/A | /B] [+ ...]] [destination [/A | /B]]

            source       Specifies the file or files to be copied.
            /A           Indicates an ASCII text file.
            /B           Indicates a binary file.
            /D           Allow the destination file to be created decrypted
            destination  Specifies the directory and/or filename for the new file(s).
            /V           Verifies that new files are written correctly.
            /N           Uses short filename, if available, when copying a file with a
                         non-8dot3 name.
            /Y           Suppresses prompting to confirm you want to overwrite an
                         existing destination file.
            /-Y          Causes prompting to confirm you want to overwrite an
                         existing destination file.
            /Z           Copies networked files in restartable mode.
            /L           If the source is a symbolic link, copy the link to the target
                         instead of the actual file the source link points to.

          The switch /Y may be preset in the COPYCMD environment variable.
          This may be overridden with /-Y on the command line.  Default is
          to prompt on overwrites unless COPY command is being executed from
          within a batch script.

          To append files, specify a single file for destination, but multiple files
          for source (using wildcards or file1+file2+file3 format).


          acidblue

            Topic Starter


            Rookie

            Re: Batch file help
            « Reply #8 on: July 29, 2010, 01:25:06 PM »
            *censored* that sux.
            I wonder why 'xcopy' not working.
            I can call it from the cmd line, just can't get it to work in a batch script.

            southpaw63119



              Beginner
            • Thanked: 3
              • Yes
              • Yes
            • Experience: Experienced
            • OS: Linux variant
            Re: Batch file help
            « Reply #9 on: July 29, 2010, 01:34:13 PM »
            Try running the following:


            Code: [Select]
            xcopy c:\pix.jpg c:\pix2.jpg /Y
            PAUSE

            From your batch file (do NOT use @echo off), and let us know if the command line still just sits there, or what, if anything, shows up in the command prompt.
            This is why we can't have nice things.

            acidblue

              Topic Starter


              Rookie

              Re: Batch file help
              « Reply #10 on: July 29, 2010, 01:39:13 PM »
              My cmd screen goes crazy.
              Text goes by so fast I can hardly read it.
              I have to close the window to get it to stop.

              Obviously somethings wrong.

              Salmon Trout

              • Guest
              Re: Batch file help
              « Reply #11 on: July 29, 2010, 01:39:51 PM »
              Have you got any batch files called xcopy.bat or xcopy.cmd in a folder on your PATH? Or in the same folder as your batch that you are testing? It isn't called xcopy.bat is it? Do you have write permissions for the C:\ root folder? Are there actually any files to copy? Do you really want to fill up the root folder of your C:\drive with jpegs?




              Salmon Trout

              • Guest
              Re: Batch file help
              « Reply #12 on: July 29, 2010, 01:42:50 PM »
              Text goes by so fast I can hardly read it.

              try this - pipe the output of xcopy through more (which is like less on 'nix)

              Code: [Select]
              xcopy c:\pix.jpg c:\pix2.jpg /Y | more

              acidblue

                Topic Starter


                Rookie

                Re: Batch file help
                « Reply #13 on: July 29, 2010, 01:54:21 PM »
                Have you got any batch files called xcopy.bat or xcopy.cmd in a folder on your PATH? Or in the same folder as your batch that you are testing? It isn't called xcopy.bat is it? Do you have write permissions for the C:\ root folder? Are there actually any files to copy? Do you really want to fill up the root folder of your C:\drive with jpegs?




                OMG, I don't believe I didn't catch that.
                Yes I had a file called xcopy.bat in the same folder :||x
                I feel so stupid.

                No I don't want to fill up my root folder with jpg's.
                I have image files spread out all over my PC.
                I want to collect them all and compress them into a zip or tar file.
                Then upload them to my server for safe keeping.

                southpaw63119



                  Beginner
                • Thanked: 3
                  • Yes
                  • Yes
                • Experience: Experienced
                • OS: Linux variant
                Re: Batch file help
                « Reply #14 on: July 29, 2010, 01:57:09 PM »
                Nice catch Salmon Trout.

                (the pun just might be intended)
                This is why we can't have nice things.