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

Author Topic: spaces and batch files  (Read 3801 times)

0 Members and 1 Guest are viewing this topic.

dazza56

    Topic Starter


    Greenhorn

    spaces and batch files
    « on: April 10, 2009, 02:59:06 AM »
    Hi,I am trying to find a way to copy a file (*.pst) to somewhere else that I choose.
    I am using the windows XP and running as *.bat  AND *.cmd

    It looks like this:
    ======================
    @echo off
    cd\
    dir *.pst /s /b >pst.txt
    ======================

    The output txt file looks like this:
    ======================
    C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\archive.pst
    C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\Outlook1.pst
    ======================

    My problem is that obviously my output file cannot put Quotes around each location, or at least I don't know how to.
    Also even if I go in and manually put quotes in place by editing my "copy batch file" it will only go as far as the 1st space and then creates an error.

    My Copy Batch file looks like this:
    ======================
    cd c:\
    for /F %%a in (pst.txt) do xcopy "%%a" C:\backup /n
    pause
    ======================

    As you can see I have tried (in the above example) to wrap the %%a variable in quotes, that doesn't work either.
    This is the error I get when it runs:
    ======================
    Hi,I am trying to find a way to copy a file (*.pst) to somewhere else that I choose.
    I am using the windows XP and running as *.bat AND *.cmd

    It looks like this:
    ======================
    @echo off
    cd\
    dir *.pst /s /b >pst.txt
    ======================

    The output txt file looks like this:
    ======================
    C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\archive.pst
    C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\Outlook1.pst
    ======================

    My problem is that obviously my output file cannot put Quotes around each location, or at least I don't know how to.
    Also even if I go in and manually put quotes in place my "copy batch file" it will only go as far as the 1st space and the creates an error.

    My Copy Batch file looks like this:
    ======================
    cd c:\
    for /F %%a in (pst.txt) do xcopy "%%a" C:\backup /n
    pause
    ======================

    As you can see I have tried (in the above example) to wrap the %%a variable in quotes, that doesn't work either.

    This is the error I get when it runs:
    ======================

    C:\Documents and Settings\Darrell\Desktop\get PST>cd c:\

    C:\>for /F %a in (pst.txt) do xcopy "%a" C:\backup /n

    C:\>xcopy "C:\Documents" C:\backup /n
    File not found - Documents
    0 File(s) copied

    C:\>xcopy "C:\Documents" C:\backup /n
    File not found - Documents
    0 File(s) copied

    C:\>pause
    Press any key to continue . . .
    ==========================================
    As you can see it only reads C:\Documents and then stops, Can anybody help with this? I hope I have given you enough info. Daz

    dazza56

      Topic Starter


      Greenhorn

      Re: spaces and batch files
      « Reply #1 on: April 10, 2009, 03:04:34 AM »
      Sorry about the 1st attempt at pasting my question. Somehow it did it twice.
      Here is the actal question in full.
      Hi,I am trying to find a way to copy a file (*.pst) to somewhere else that I choose.
      I am using the windows XP and running as *.bat AND *.cmd

      It looks like this:
      ======================
      @echo off
      cd\
      dir *.pst /s /b >pst.txt
      ======================

      The output txt file looks like this:
      ======================
      C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\archive.pst
      C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\Outlook1.pst
      ======================

      My problem is that obviously my output file cannot put Quotes around each location, or at least I don't know how to.
      Also even if I go in and manually put quotes in place my "copy batch file" it will only go as far as the 1st space and the creates an error.

      My Copy Batch file looks like this:
      ======================
      cd c:\
      for /F %%a in (pst.txt) do xcopy "%%a" C:\backup /n
      pause
      ======================

      As you can see I have tried (in the above example) to wrap the %%a variable in quotes, that doesn't work either.

      This is the error I get when it runs:
      ======================

      C:\Documents and Settings\Darrell\Desktop\get PST>cd c:\

      C:\>for /F %a in (pst.txt) do xcopy "%a" C:\backup /n

      C:\>xcopy "C:\Documents" C:\backup /n
      File not found - Documents
      0 File(s) copied

      C:\>xcopy "C:\Documents" C:\backup /n
      File not found - Documents
      0 File(s) copied

      C:\>pause
      Press any key to continue . . .
      ==========================================
      As you can see it only reads C:\Documents and then stops, Can anybody help with this? I hope I have given you enough info. Daz

      Dusty



        Egghead

      • I could if she would, but she won't so I don't.
      • Thanked: 75
      • Experience: Beginner
      • OS: Windows XP
      Re: spaces and batch files
      « Reply #2 on: April 10, 2009, 03:25:33 AM »
      Welcome to the CH forums.

      Quote
      My Copy Batch file looks like this:
      ======================
      cd c:\
      for /F %%a in (pst.txt) do xcopy "%%a" C:\backup /n
      pause
      ======================

      Amend your For command line to include "Delims=*" and see what happens.

      Good luck
      One good deed is worth more than a year of good intentions.

      dazza56

        Topic Starter


        Greenhorn

        Re: spaces and batch files
        « Reply #3 on: April 10, 2009, 03:31:11 AM »
        Excellent. That worked perfectly. I probably should have asked this question earlier today and saved about 4 hours of frustration. Thanks a lot.  :D

        Dusty



          Egghead

        • I could if she would, but she won't so I don't.
        • Thanked: 75
        • Experience: Beginner
        • OS: Windows XP
        Re: spaces and batch files
        « Reply #4 on: April 10, 2009, 03:35:25 AM »
        You're very welcome and thanks for coming back to report your success..

        One good deed is worth more than a year of good intentions.

        dazza56

          Topic Starter


          Greenhorn

          Re: spaces and batch files
          « Reply #5 on: April 10, 2009, 04:01:43 AM »
          Can you explain what that edit does exactly please?

          Dusty



            Egghead

          • I could if she would, but she won't so I don't.
          • Thanked: 75
          • Experience: Beginner
          • OS: Windows XP
          Re: spaces and batch files
          « Reply #6 on: April 10, 2009, 04:51:28 AM »
          I'm no expert but...

          The For command parses input until a delimiter is found.  The default delimiters are space and tab.  In your script the first line of pst.txt would be parsed until a space was encountered at which point %%a would be set to the value C:\Documents 

          By using "Delims=*" the default delimiters no longer apply.  "Delims=" could also have been used as could any character which does not appear in the input being parsed.

          As you will know entering For/? at the Command Prompt displays info on the For command.
          One good deed is worth more than a year of good intentions.

          dazza56

            Topic Starter


            Greenhorn

            Re: spaces and batch files
            « Reply #7 on: April 10, 2009, 05:17:16 AM »
            I understand. Thanks again.