XCOPY to only look back one day - batch-file

I have a current .BAT file that is functional but I need to be more specific with it. Currently, it will only copy over files that do not exist. What I am wanting to do is to only look back ONE day and copy those files. I have posted my file information below. Thank you in advance for the assistance.
XCOPY /y "w:\EFileRequests\*.xml" "\\DIS2\EFilingXML\Archive\"/D

Use robocopy, it has a parameter for exactly what you want.
/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.

Related

How to get a real time progress bar for copying a large file (2.2 GB) with a batch file?

I'm making a batch script, but I don't know on how to make a real time progress bar for copying a large file.
Could you help me out?
I'd rather use the standard COPY in batch file, not XCOPY or ROBOCOPY.
My current code is (not all of it):
copy %userprofile%\desktop\target.ipsw %TMP%\downgrade\target.ipsw
The Esentutl /y option allows copyng (single) file files with progress bar like this :
For the sake of your directories, this is what the code will look like:
esentutl /y "%userprofile%\desktop\target.ipsw" /d "%TMP%\downgrade\target.ipsw" /o
Please keep in mind that there are a few limitations to the esentutl command:
You can only copy one file at a time.
The /y syntax was presented in windows vista.
You cannot overwrite files. (You will have to have batch check the destination beforehand and if needed, delete the previous file)

Batch file to transfer files with certain phrase in name

I currently use a batch code which transfers files from one place to another. I wish to elaborate on that code to only transfer files which have a certain phrase in their file name.
I did not write the code, and I do not fully understand it but I know what is does.
REM choose desired drive
cd \
Z:
REM change to required directory
cd out
REM cpy all files using * to the desired directory
copy *.dat \\server\f\rug_data\received_transfer
REM delete all files in the folder
REM del *.usr
All I want to do now is add a bit which says only transfer files with 'D0036' in their name.
I have spent time googling but could not find exactly what I was after.
Any help greatly appreciated.
change
copy *.dat \\server\f\rug_data\received_transfer
to
copy *D0036* \\server\f\rug_data\received_transfer
OR, if you mean "All .dat files with D0036 in their name"
copy *D0036*.dat \\server\f\rug_data\received_transfer
* means "match any number of any characters"
Like this?
copy *D0036*.dat \\server\f\rug_data\received_transfer
This works like a charm!
move /-y "C:\(Folder that the contains files)*(Specify a certain character)*" "C:\(Dest Folder)"
This will move everything in the folder with the name that you wrote.
Hope it works!
Logan

create a batch file which copies text files of specified date

I want to create a batch file which copies text file by taking user input. As an input user give from date and to date. The name of the text files are like: error_log_04_06_2011
Now for example I want data from 04/06/2011 to 07/06/2011, so i can do that by using xcopy command like this
#ECHO OFF
SET /P f=Please Enter from date(m-d-yyyy):
SET /P t=Please Enter to date(mm-dd-yyyy):
mkdir d:\bkp
xcopy /S /D:%f% /EXCLUDE:%t% C:\Emulator\Log_Data d:\bkp
This will copy all the file from the date mentioned. Now I want to give "to" date also.so i can copy files of a certain period.
One approch is that I use delete command and delete extra files that are copied. But Delete command doesnt have any switch regarding date. So plz help.....
Unfortunately, there isn't much that can help in this area built-in to batch/cmd. dir can take a flag to order its output by modified time, but I'm guessing you want it to depend on just the filenames and it still wouldn't give you the range you want.
The filename you have shown isn't sortable. If they were named in YYYY_MM_DD format, you could find the files in the date range with sort and a for loop.
Without that, you will end up needing to do date math to generate each individual date in your range, convert each date to your filename format, and pass that to copy.
Rob Van Der Woude has a good list of date functions in batch, including the harder date math. It would be a good place to start. http://www.robvanderwoude.com/battech.php#Time
I haven't tried it, but you could use the xcopy /d and /l switches to generate lists of files that are dated after a certain date to avoid doing the maths.
After the xcopy from the first date you could drive a delete in a for /l loop from a list of file dated after the second date.

XCOPY exclude list ignored after first exclusion

I have a batch file I've created which uses xcopy to copy a dir, and child dirs, and merge them into one file. (ie. all my modulised development css stylesheets merged into one production stylesheet).
Everything is good, apart from the fact that when I reference the excludelist.txt, it only excludes the first line, and not the subsequent files I want excluded.
Anyone fancy a crack at this? You'd be most helpful.
Here's the code:
XCOPY C:\xampp\htdocs\PROJECT\css\*.* C:\temp /S /I /Y /EXCLUDE:C:\xampp\htdocs\PROJECT\exclude.txt
...and inside my exclude.txt is...
1.css
2.css
3.css
4.css
5.css
///// I know the code works (to an extent) because it is infact excluding file 1.css -- just not the ones below it. Am I right to put each exclusion on a new line?
I use the following,
xcopy "C:\users\dad\*.*" dad /s /d <yesnoyesno /EXCLUDE:excluexclu 1>cop.txt 2>err.txt
as somewhere on the web I saw a note to the effect that the /Y switch could not be used directly with an exclude file.
What I wanted to point out here, was the useful output files 1 & 2, which detail the success & failure issues.
Mine shows only success.
The short answer: Create a new text file, type the entries and save the file.
The longer explanation: I ran into this very issue on a Windows 2008 server today. I tried all kinds of things to get it to work. Forced notepad to save the file as ANSI, Unicode and UTF-8 but all of them had the same problem. Finally I started thinking about the fact that I put the file on the server via FTP and it's quite likely that FTP tweaked the file format. I created a new text file on the server, typed all the same entries in the new file and now it works.
I had a similar problem. I was trying to exclude all files with a certain extension in the root folder and any sub-folders and it didn't work. The reason was I was putting *.pdb instead of just .pdb. The newline/carriage return thing was a total red herring for me.
So my file just looked like:
.pdb
.obj
.vb
.cs
You seem to be using xcopy correctly - each exclusion file (or match depending on wildcards) should be on a new line within the file. So far I've been unable to reproduce the behaviour you're experiencing.
Is the exclude.txt listing you've given above a test file, or are they the actual css names?
What are the names of the other files that your batch file is supposed to copy?
Edit:
That the xcopy is failing to exclude further files after a single match is giving me most pause. I thought it might be to do with the type of carriage-return that was used in the exclude file, but xcopy handles unix-style carriage-returns just fine.
Can you re-verify that the correct exclude file is being used?
Try forcing it to save with ANSI encoding on your text editor.
I was having a similar issue and that did it.

How to say no to all "do you want to overwrite" prompts in a batch file copy?

By default, copying from the command prompt will prompt you to overwrite files that already exist in the target location.
You can add "/Y" to say "Yes to all" replacements.
But how can you say "No to all" ?
In other words, I want to copy everything from one directory that does not already exist in the target.
The closest thing I see is the XCOPY argument to only copy things after a specific mod-datetime.
Unless there's a scenario where you'd not want to copy existing files in the source that have changed since the last copy, why not use XCOPY with /D without specifying a date?
echo "No" | copy/-Y c:\source c:\Dest\
You can make a text file with a single long line of "n" then run your command and put < nc.txt after it. I did this to copy over 145,000 instances where "No overwrite" was what I wanted and it worked fine this way.
Or you can just hold the n key down with something, but that takes longer than using the < to pipe it in.
Here's a workaround. If you want to copy everything from A that does not already exist in B:
Copy A to a new directory C.
Copy B to C, overwriting anything that overlaps with A.
Copy C to B.
I use XCOPY with the following parameters for copying .NET assemblies:
/D /Y /R /H
/D:m-d-y - Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
/Y - Suppresses prompting to confirm you want to overwrite an existing destination file.
/R - Overwrites read-only files.
/H - Copies hidden and system files also.
I know you all think /D: date is going to use date stuff, but just /D without the: does exactly what we want so...
xcopy {Source} {Destination} /E /D
Will copy without overwriting to pickup those files that are new or maybe failed before for some reason.
Just try it, it works.
I expect xxcopy has an option for that.
Bingo:
http://www.xxcopy.com/xxcopy27.htm#tag_231
2.3 By comparison with the file in destination
The switches in this group select files based on the
comparison between the files in the source and those in
the destination. They are often used for periodic backup
and directory synchronization purposes. These switches
were originally created as variations of directory backup.
They are also convenient for selecting files for deletion.
2.3.1 by Presence/Absence
The /BB and /U switches are the two switches which select
files by the pure presence or absence as the criteria.
Other switches in the this group (Group 2.3) are also
affected by the file in the destination, but for a
particular characteristics for comparison's sake.
/BB Selects files that are present in source but not in destination.
/U Selects files that are present in both source and destination.
-Adam
this works fine
no | cp -rf c:\source c:\Dest\
echo N | copy /-y $(SolutionDir)SomeDir $(OutDir)
Try this:
robocopy "source" "destination" /e /b /copyall /xo /it
Copy that line into notepad and save as a .bat file. Run the file and it will copy everything from the source to the destination. When you run it again it will not replace files that are identical. when you change or a file changes it will replace the file at the destination.
test it out. I created a .txt file with a few works, ran the script, change the wording on the .txt file and ran the script again, it replace only the change file from the source.
/e=Copies subdirectories. Note that this option includes empty directories
/b=Copies files in Backup mode
/copyall=Copies all file information
/xo=Excludes older files. (this is what prevents it from copy the same file over and over)
/it=Includes "tweaked" files. (this will allow the copy and replace of modified files)
Thanks for this. I am using the command line utility AzCopy (v 3.1.0.93) to move ~1 million files from my local PC to my Azure blob storage. I've got some duplicates and cannot babysit the copy to answer each prompt and don't want to re-upload the same file.
The AzCopy utility offers a /Y command to suppress the confirmation prompts but ends up telling it to overwrite the destination file. Going this route I was able to get it to NOT re-upload the file. However, it does seem like a bit of a hack since it is not actually answering the prompt with "No", instead I get the error "No input is received when user needed to make a choice among several given options." but does not upload the file.
Here is the command I used: echo n | AzCopy /Source:"{file path}" /Dest:"{blob storage URL}" /DestKey:{key}
Hope this helps the next guy.
Depending on the size and number of files being copied, you could copy the destination directory over the source first with "yes to all", then do the original copy you were doing, also with "yes to all" set. That should give you the same results.
We used "robocopy" through "invoke-command" to copy a huge amount of VMs in our environment. We've discovered that "robocopy" unexpectedly exits sometimes and the whole proccess goes to down. So we've decided to use "xcopy". Now we're checking it's work and to "create" "Not for all" option we use that function (powershell):
function gen_long_no([string]$path) {
$result = ""; Get-ChildItem $path -Recurse | ? { if ($_.PSIsContainer -eq $false) { $result += "n" } };
return $result
}
Maybe helps somebody.
Adding the switches for subdirectories and verification work just fine.
echo n | xcopy/-Y/s/e/v c:\source*.* c:\Dest\

Resources