copy with command line does not copy the complete file

Attached is my code and it will work on a small file, but the Access file which is large will not copy the complete file.  

I am using a bat file and then using the Task Scheduler to execute the backup on a schedule.

I there a better way to backup a single file auto based on a time frame?

This is my code:   copy c:\WorkKeys.mdb+\*%date:~4,2%%date:~7,2% f:
Don-WhiteAsked:
Who is Participating?
 
NrisimhaConnect With a Mentor Commented:

This one works for me. It copy a file of 20 MB correctly.And try that:

copy /B c:\WorkKeys.mdb+\*%date:~4,2%%date:~7,2% f:\WorkKeys.mdb

Nrisimha
0
 
AllTripCommented:
copy c:\test\test.txt c:\windows\test.txt

This is move how you need to write it up.  You need to include the file extension and also need to retype the file name in the directory you want to place the file.
0
 
ChrissalterCommented:
Is the database in use while the backup is in operation?

That would definately cause the copy to fail

You could try copying the file to the same directory first and then copy it to the other directory
But if any part of the database changes during the copy it WILL fail
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Don-WhiteAuthor Commented:
This is the code.  It only copies 8kb not the complete access file.

copy c:\WorkKeys.mdb+\*%date:~4,2%%date:~7,2% f:\WorkKeys.mdb
0
 
CSIPComputingCommented:
Try using the BINARY switch /B...

Database files can have all sorts of odd characters in them, and one of them could be being interpreted as a false End Of File marker.

The /B switch will solve this.
0
 
Don-WhiteAuthor Commented:
The db is not in use.

I tried this and it only copied 8 kb not complete file.

copy c:\WorkKeys.mdb+\*%date:~4,2%%date:~7,2% /b f:\WorkKeys.mdb
0
 
CSIPComputingCommented:
Silly question...

What is the SOURCE file called?  (my guess is WorkKeys.mdb).

Where is the SOURCE file? (My guess is C:\)

Where are you trying to copy it to? (My guess is F:\)

What are you trying to do with the Date info?  (I cannot figure out!)

If you type "Copy C:\WorkKeys.mdb F:\WorkKeys.mdb /B" does it work?
0
 
CSIPComputingCommented:
Reason I ask is that I get a syntax error when trying your command line!
0
 
Don-WhiteAuthor Commented:
My code works OK except it does not copy the whole file
I want the file in drive F to have the current date and not the date of the copied file.

You assumptions are correct.

Is there a better way to do what I need to do?
0
 
Bill PrewCommented:
Exactly what file(s) are you trying to copy?  The syntax you are using with a + in the middle of the first COPY command parameter normally indicates you want to concatenate two (or more) files together.  But if the first of those is an MDB as you show then I don't understand why you would want to join other files onto that MDB file in the destination?  Can you describe what you need to do?

~bp
0
 
Don-WhiteAuthor Commented:
I tried it and it worked, but left the command lines on the desktop.  How to clear that?

Attached is the screen
Screen.docx
0
 
Don-WhiteAuthor Commented:
It did work and finally the command line closed when the file was completely copied.  Thanks, for your excellent help and Merry Christmas and a Happy New Year.

Don
0
 
CSIPComputingCommented:
Nothing for the fact that you were missing the /B...

<sigh>
0
 
NrisimhaCommented:


Well, you have to put a BAT file in some folder not on the Desktop.!!!
And you know how to execute a BAT file with a Task Scheduler.

You choose a time when you want to copy that MDB file.

And in a case that MDB file already exists in the F:\ you need to add a /Y switch in a command line.
It doesn't ask then do you want to overwrite the old WorkKeys.mdb file in the F: root.

So, the command look like:

copy /B /Y c:\WorkKeys.mdb+\*%date:~4,2%%date:~7,2% f:\WorkKeys.mdb



Nrisimha
0
 
Don-WhiteAuthor Commented:
I want to keep multicopies in the f drive.  How do I do that?
0
 
Bill PrewCommented:
I know the question is closed, and I may be missing something, but I'm still concerned that Don-White may not be getting what he wants.  The way the command is written it will do the following:

Concatenate the file C:\WorkKeys.mdb with any other files in the root of the current directory (likely C:\) that start with anything and contain 1219 in their file name.  This single concatenated file will be copied to the file F:\WorkKeys.mdb.

This doesn't feel like anything useful, and appears that the date logic is not affecting the copy at all, and the result is the same as:

copy C:\WorkKeys.mdb F:\WorkKeys.mdb

~bp
0
 
NrisimhaCommented:


This doesn't feel like anything useful, and appears that the date logic is not affecting the copy at all, and the result is the same as:

copy C:\WorkKeys.mdb F:\WorkKeys.mdb

Of course it is not the same, because your command copy C:\WorkKeys.mdb F:\WorkKeys.mdb will copy a file WorkKeys.mdb from the C:\ to F:\, but will have ORIGINAL date of input file on C:\ !!!

But, Don-White want to copy C:\WorkKeys.mdb file with a date taken in the moment of copying this file !!!

But, why didn't you try first that command from CLI and then you could see these differences:

Original file

MDB1
After copying with command copy /Y C:\WorkKeys.mdb F:\WorkKeys.mdb:

 MDB2
The date is the SAME !!!


And now, copying with command copy /B /Y c:\WorkKeys.mdb+\*%date:~4,2%%date:~7,2% f:\WorkKeys.mdb:

The original file on C:\ is the same.

After copying with above code copy /B /Y c:\WorkKeys.mdb+\*%date:~4,2%%date:~7,2% f:\WorkKeys.mdb you will get a f:\WorkKeys.mdb file with a current date:

 MDB3
regards

Nrisimha
0
 
Bill PrewCommented:
Okay, if that was indeed the intention (not sure I saw that stated anyplace), then a preferred approach would be:

command copy /B /Y c:\WorkKeys.mdb+nul f:\WorkKeys.mdb

Open in new window

or

command copy /B /Y c:\WorkKeys.mdb+,, f:\WorkKeys.mdb

Open in new window

these accomplish that task, and don't confuse things by referencing nonexistent files with the %DATE% variable.

~bp

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.