PDA

View Full Version : Batch file problems



ubergeek85
05-09-2008, 04:41 PM
Hi guys. For some reason a demo batch file I made isn't working. All it's supposed to do is create some folders (one with a variable as a name), and copy a bunch of different file types to the folder with the variable as a name.



@echo off
: backup.bat
cd..
cd..
cd..
cd..
cd..
cd..
cd..
cd..
cd..
echo At root directory
: This is to make sure we are in the root directory.
mkdir Backups
echo Made Backups folder
: Makes the directory. It assumes that there isn't one already called that.
: It's really designed to round up all elegibile files into a directory, for copying onto a CD or similar medium.
cd Backups
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
: Sets the folder variable, uses US date format, MM/DD/YYYY
mkdir %folder%
echo Made dated folder, date used is %folder%
cd..
copy *.txt c:\Backups\%folder\
: Text files
copy *.jpg c:\Backups\%folder\
copy *.gif c:\Backups\%folder\
copy *.jpeg c:\Backups\%folder\
copy *.jpe c:\Backups\%folder\
copy *.bmp c:\Backups\%folder\
: Images
copy *.doc c:\Backups\%folder\
copy *.docx c:\Backups\%folder\
copy *.xls c:\Backups\%folder\
copy *.xlsx c:\Backups\%folder\
copy *.mdb c:\Backups\%folder\
copy *.accdb c:\Backups\%folder\
copy *.pub c:\Backups\%folder\
copy *.ppt c:\Backups\%folder\
copy *.pptx c:\Backups\%folder\
: Most Microsoft Office files
echo Copied files
: End

And it gives this:


C:\Documents and Settings\student\Desktop>backup
At root directory
A subdirectory or file Backups already exists.
Made Backups folder
A subdirectory or file 2008_09_05 already exists.
Made dated folder, date used is 2008_09_05
Copy of New Wordpad Document.txt
The system cannot find the path specified.
0 file(s) copied.
Copy of New Wordpad Document.jpg
The system cannot find the path specified.
0 file(s) copied.
Copy of New Wordpad Document.gif
The system cannot find the path specified.
0 file(s) copied.
*.jpeg
The system cannot find the file specified.
0 file(s) copied.
*.jpe
The system cannot find the file specified.
0 file(s) copied.
*.bmp
The system cannot find the file specified.
0 file(s) copied.
New Wordpad Document.doc
The system cannot find the path specified.
0 file(s) copied.
*.docx
The system cannot find the file specified.
0 file(s) copied.
*.xls
The system cannot find the file specified.
0 file(s) copied.
*.xlsx
The system cannot find the file specified.
0 file(s) copied.
*.mdb
The system cannot find the file specified.
0 file(s) copied.
*.accdb
The system cannot find the file specified.
0 file(s) copied.
*.pub
The system cannot find the file specified.
0 file(s) copied.
*.ppt
The system cannot find the file specified.
0 file(s) copied.
*.pptx
The system cannot find the file specified.
0 file(s) copied.
Copied files
C:\>

For some reason no files are copied to %folder%. Any idea why?
Thanks.

Bantu
05-09-2008, 05:16 PM
Not sure geekster. I use this to backup my outlook.pst file.
The bat file is on D: and when run it copies and overwrites the destination whenever I run it as I want it to do. Works great for me if C ever crashes. Schedule runs it every couple of days. Outlook has to be closed at the time it runs.

copy "C:\Documents and Settings\PC1\Application Data\Microsoft\Outlook\Outlook.pst" E:\Outlook2003Backup.pst

dyewitness
05-09-2008, 05:23 PM
Your copy commands havea typo:
...%folder\ instead of %folder%

Rod J
06-09-2008, 07:03 PM
A little tip ...

It's more efficient and guaranteed to get to the root folder no matter how many directories deep you are using this: "CD \" rather than a series of "CD .."

johnd
06-09-2008, 08:42 PM
You need to use some code like this:

IF EXIST DirectoryName GOTO end
md directoryName
:end

ubergeek85
08-09-2008, 12:18 PM
Your copy commands havea typo:
...%folder\ instead of %folder%

That did it. Thanks.