Computer Hope

Microsoft => Microsoft DOS => Topic started by: dazza56 on April 10, 2009, 02:59:06 AM

Title: spaces and batch files
Post by: dazza56 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
Title: Re: spaces and batch files
Post by: dazza56 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
Title: Re: spaces and batch files
Post by: Dusty 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
Title: Re: spaces and batch files
Post by: dazza56 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
Title: Re: spaces and batch files
Post by: Dusty on April 10, 2009, 03:35:25 AM
You're very welcome and thanks for coming back to report your success..

Title: Re: spaces and batch files
Post by: dazza56 on April 10, 2009, 04:01:43 AM
Can you explain what that edit does exactly please?
Title: Re: spaces and batch files
Post by: Dusty 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.
Title: Re: spaces and batch files
Post by: dazza56 on April 10, 2009, 05:17:16 AM
I understand. Thanks again.