Messed-up batch file :(

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jkaufman101
Posts: 4
Joined: 31 Dec 2016 19:07

Messed-up batch file :(

#1 Post by jkaufman101 » 31 Dec 2016 19:26

I'm trying to write a quick batch file to back up my Outlook 2016 folders (C: drive) to a USB drive (F: drive). It worked for a long time but ever since I reformatted my C: drive, it stopped working. The notepad I use on my desktop (which I click on containing the script) flashes on the my monitor and then flashes of the screen, all in a microsecond.

This is what I've written:

c:
cd C:\Users\digis\Outlook
copy *.* F:\Outlook 2016 back-up folder

Thanks a lot!

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Messed-up batch file :(

#2 Post by aGerman » 01 Jan 2017 06:29

At least your target folder contains spaces and thus, must be enclosed into quotation marks.
untested:

Code: Select all

@echo off
set "source=C:\Users\digis\Outlook"
set "target=F:\Outlook 2016 back-up Folder"

if not exist "%target%\" md "%target%"

cd /d "%source%"
copy *.* "%target%\"
pause

The PAUSE at the end keeps the window opened. Now you can observe error messages. If everything works okay you can remove the PAUSE command.

Steffen

jkaufman101
Posts: 4
Joined: 31 Dec 2016 19:07

Re: Messed-up batch file :(

#3 Post by jkaufman101 » 01 Jan 2017 13:19

aGerman wrote:At least your target folder contains spaces and thus, must be enclosed into quotation marks.
untested:

Code: Select all

@echo off
set "source=C:\Users\digis\Outlook"
set "target=F:\Outlook 2016 back-up Folder"

if not exist "%target%\" md "%target%"

cd /d "%source%"
copy *.* "%target%\"
pause

The PAUSE at the end keeps the window opened. Now you can observe error messages. If everything works okay you can remove the PAUSE command.

Steffen

jkaufman101
Posts: 4
Joined: 31 Dec 2016 19:07

Re: Messed-up batch file :(

#4 Post by jkaufman101 » 01 Jan 2017 18:24

untested:
[code]
@echo off
set "source=C:\Users\digis\Outlook"
set "target=F:\Outlook 2016 back-up Folder"
----------------------------------------------------------
As I took your suggestion above, didn't work, so i went back and wrote this one:

cd C:\Users\digis\Outlook copy *.*
F:\Outlook 2016 back-up
pause

---and then I get these errors appearing underneath:

C:\Users\digis\Desktop>cd C:\Users\digis\Outlook copy *.*
The filename, directory name, or volume label syntax is incorrect.

C:\Users\digis\Desktop>F:\Outlook 2016 back-up
'F:\Outlook' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\digis\Desktop>pause
Press any key to continue . . .


Hmmmm...

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Messed-up batch file :(

#5 Post by aGerman » 02 Jan 2017 02:10

"didn't work" is nothing from what I could ever deduce what happened. Also CD and COPY in the same line can't work and as I already told you pathes with spaces have to be enclosed into quotation marks.

Instead of randomly trying funny things I would like you to
1) Run the script that I provided to you and post the messages that it outputs
2) Check if the pathes are correct and existing
3) Tell me whether or not the files you want to copy are directly placed in C:\Users\digis\Outlook or rather in subfolders.

Steffen

jkaufman101
Posts: 4
Joined: 31 Dec 2016 19:07

Re: Messed-up batch file :(

#6 Post by jkaufman101 » 02 Jan 2017 19:28

You were right and I was wrong. This works fine now. Thank you very much!

Post Reply