We use cookies to provide you with a better experience. If you continue to use this site, we'll assume you're happy with this. Alternatively, click here to find out how to manage these cookies

hide cookie message
Contact Forum Editor

Send an email to our Forum Editor:


PLEASE NOTE: Your name is used only to let the Forum Editor know who sent the message. Both your name and email address will not be used for any other purpose.

Tech Helproom


It's free to register, to post a question or to start / join a discussion


 

Batch file problem, yet again


Housten

Likes # 0

Good afternoon,

I have started this thread because I am having a problem that is ‘so simple’ it is driving me mad, Eric10 and lotvic must be as annoyed as I am.

I am trying to write a batch file to make backups and copies of various files, as and when I wish/want to have them made. I have had a load of problems, but I thought I had solved the copying one yesterday when I found a one liner that copied a test that I made a batch file for. Now it won’t and I do not know why! I have listed the file below and when it runs apart from saying ‘0 files copied’ it now states ‘The filename, directory name or volume label syntax is incorrect’. I have created – and deleted – the target folders and there is no change in the error message. Now I have tried the switches in font of and behind the folder names, the folder names with and without commas, one with and without commas and I have no idea as to why I am getting this error. So if someone could tell what/where/why I am making this error I would be very grateful. [ I should also let you know that this is not the first error I have made, nor will it be the last!!! ]. The batch file is:-

ECHO OFF

xcopy "C:\QUICKEN DATA\" W:\TEMP1 /S /D /Y /M /E /V /C /Q /G /H /J

I do not know what has now happened, but in testing to make sure that that previous error was the one I am still getting, I have got a new error! It is now stating that there is an ‘Invalid path’. Which confuses me even more, because ‘W\TEMP!’ is a temporary folder I have created especially for tests to be made. I have also got a pen drive plugged in and it is giving the same error!

Does any kind person have any ides what stupidity I am committing?

Many, many thanks in anticipation.

Like this post
Eric10

Likes # 0

In your explanation you have typed TEMP! but I think that is just a typing error while posting as ! is on the same key as 1.

Your problem is that you haven't specified any files to be copied by xcopy.

you need to use:

xcopy "C:\QUICKEN DATA\*.*" W:\TEMP1 /D /Y /M /E /V /C /Q /G /H /J

I've removed the /S switch because /E will copy all folders whether they are full or empty so /S is unnecessary. It is also a good idea to remove /M while you are testing because with /M in place the files will only copy once unless you unset the archive attribute on the files and folders in "C:\Quicken Data" after each run. If you don't unset the attribute you will get the "0 files copied" message.

I've also had to resort to some trickery to make the code display correctly on the forum so that you can copy and paste it as it is.

Like this post
Eric10

Likes # 0

Well Housten, I've just learned something new myself. It appears that using /D without any date parameters prevents files being overwritten unless the source file is newer than the target file. This may have been the cause of the "0 files copied" messages you have been getting so perhaps you should remove that also while testing the batch file. You can always put /M and /D back in once everything is working ok.

Like this post
Housten

Likes # 0

Eric10,

Well I'm blowed!! IT WORKED!! I am certain that I must have done what you have suggested, but it did not work for me!! But yours works that all I care about, so many, many, many thanks. And your other suggestion of removing '/d' and '/m' may well have something to do with it!!

Anyway I am now proceeding to further problems, so - being very selfish - I hope you will continue to watch out for many more [ I am hoping for none, but I know that's impossible! ] of my mistakes!!

I will let you know when it is up and running!! More to the point, how long it takes! I mean if it takes 20 minutes that's worthwhile, but if it takes 20 hours, then.............Heigh Ho!!

I will have to see how it goes, but I can't thank you enough!

Like this post
Eric10

Likes # 0

Housten

I glad it works for you. I think that a lot of the problem has been that this forum uses certain characters to format the posts so what we intend to post is not always what you see printed. The asterisk and backslash characters are problematic in certain combinations.

I have writen a short backup batch program based on what you have previously posted and if you copy and paste it again it should work ok. As before, you should remove the /D and /M switches just for the purpose of testing. I've also been going on about not needing to use both the /S and /E switches together but after reading up on the Microsoft site today it would appear that I am wrong and it is quite correct to use them both so I appologise for that.

@ECHO OFF

REM Backup.bat

echo %date%

set foldermonth=%date:~6,4%-%date:~3,2%

set folder=W:\%foldermonth%

echo starting Copy

xcopy /D /M /S /E /V /C /Q /G /H /J /I /Y "C:\Quicken Data\*.*" %folder%

echo Press any key to close this box!

pause > nul

You don't need to make the destination folder in advance as xcopy will create the folder if it doesn't exist. The /I (i) switch supresses the message that asks if the destination is a File or Directory and just creates a directory. If you include the pause at the end you can run the program from a shortcut on the Desktop.

Good Luck

Eric

Like this post
Housten

Likes # 0

Eric10,

Many, many thanks for the new batch file. I am just getting round to writing my revised one, but I will shortcut this by using - and editing - your suggestions!!

What I have decided to do - and this is in no way meant to denigrate what you have written, because I will be using yours as the basis for mine - is to create a folder of 'YearMonth' and then I will have just three options - well I say 3, but all will have the possibility of being written back to where they come from - one will be, essentially, for the first of the month when a new 'YearMonth' folder will be created and a complete backup of my 'C:\' partition will be written to it. [ Yes I know it will take some time, but at least I will know what it is doing!!!! ]. The second option will be a daily backup/copy of my bank and share accounts, and the third option will be a weekly backup/copy of my 'C:\' partition. This 'weekly' copy will be done at the weekend whereas the monthly will take place on the First of the month, irrespective of the day.

This is not quite what I was going to do, but this way is, in effect, a shortcut to doing what I first thought of, of doing individual backups of different folders. In fact thinking about it further I think I will add my Excel/Word folders to the daily one. Because as I see this working if there are no new/changed files then nothing will be copied and the only thing that happens is that the file takes a little longer to run, but I have the satisfaction - he says hopefully - of having all the folders backedup without me having to decide which to do!!

I am assuming that all your 'xcopy' stuff works when I say that I am truly indebted to you for all your help. Now all I have to do is to get it all to work the way I want!!! I will let you know, but probably not until next week/month in order to see that it all works out.

Once again, and I can not emphasise this enough, many, many thanks for all your help and advice.

Like this post

Reply to this topic

This thread has been locked.



IDG UK Sites

3 of the best portable chargers: a solar power charger, a hand-cranked charger, and how to charge...

IDG UK Sites

iOS 8 review: Hands on with the iOS 8 beta

IDG UK Sites

Thinking robots: The philosophy of artificial intelligence and evolving technology

IDG UK Sites

Sharknado 2 VFX: how The Asylum created CG flying man-eating sharks