Dos command xcopy to have current date - 90 days variable - dos

i need to a .bat file to copy with xcopy command the files from a specific directory that are 90 days new. that means to take the todays date and take out 90 days of it and do not perform the copy.
help is needed,
thx

Use ROBOCOPY not XCOPY. It will do what you want very easily. Robocopy is installed on Windows 7 and is a free download for other versions.
ROBOCOPY /S /MAXAGE:90 P:\path\to\source Q:\path\to\dest
There are many other options, for minimum age, min and max size, attrributes, filtering by file and directory names, and so forth.
Also you can use the /L option to just list what it would have done, to check you have the other options right.

Related

How to copy new files only in a folder to another one in Windows?

I am looking for a way to copy new files only from a folder to another one. The criteria are:
No PowerShell.
No software, just batch shell.
Timestamp in milliseconds or seconds, not minutes.
No sync. Files on folder B can be deleted, I only need new files from folder A to by copied.
Workflow:
Watch folder A.
New file written, copy to folder B.
I have tried with xcopy and robocopy but as far as I understand, using the timestamp in both is in days while I want to compare the timestamp in milliseconds.
XCOPY
/D:mm-dd-yyyy
Copy files changed on or after the specified date.
If no date is given, copy only files whose
source date/time is newer than the destination time.
ROBOCOPY
/minage:<n> Specifies the minimum file age (exclude files newer than n days or date).
The ideal solution I have in mind (forgive my ignorance here as I am not a windows user):
#REM new_only.bat
CURRENT_TIME=%date%%time%
SOURCE_DIR="c:\source"
TARGET_DIR="c:\target"
:start
xcopy %SOURCE_DIR% %TARGET_DIR% /time>%CURRENT_TIME%
goto start

Windows Batch File to Delete Audio Files, with Length Requirement

and thank you for any help. I have tried searching for an example on how to accomplish the following, but haven't found anything. Any help would be appreciated as I have no experience in creating a BAT file!
I have a third party program that records audio, and generates an .mp3 file from it. Every 24 hours, it generates a new folder, and begins the process all over again. The problem is, even the slightest bit of sound will generate an .mp3 file. I am left with thousands of .mp3 files that are less than 1 second. I would like to delete all audio files in all of the subdirectories with a length of less than 2 seconds. How can I go about this, and is a BAT file the correct way to accomplish this? The manual way of sorting the files in the many, many directories is a very time consuming process as 20 - 30 days of files will be generated before I am able to go through them.
For a GUI solution: The shareware uncrippled Total Commander can list a full directory tree (control B) and sort by filesize (control F6) and can also display only MP3 files if needed.
This task would just need you to mark the filesizes less than x MBytes in a single pane and then you can delete them all at once.
Another solution is available with a batch file to delete MP3 files of 2.999 seconds or below:
- change [210] to [10] to delete files up to 1.999 seconds.
Download Mediainfo command line version from SourceForge
Change the path to the executable in line 2 below
Launch this batch file in the main folder of the tree of files
If the del commands you see on the screen are right then remove the echo and run it again to delete the files.
#echo off
set "exe=c:\Util\MediaInfo\MediaInfo.exe"
for /r %%a in (*.mp3) do (
"%exe%" -f "%%a" |find "Duration" | findstr /r ": 00:00:0[210]" >nul && echo del "%%a"
)
pause

How do I move files older than 30 days?

Today I was asked to come up with a script that could do the following:
check three directories on the D:\ for files older than 30 days
If there are files on there older than 30 days then move them to E:\ using the exact directory structure (this is to backup old log files to retain disc space)
We need to have a log running which would record the date, time, log name and then if the move files fails to raise an event in the event viewer or send an email to notify of error.
Now I know I will get treated like a noob, I have created some scripts to get this working by doing each step first and then trying to add them together, this always seems to fail.
Use robocopy in a batch file for this kind of task:
#echo off
robocopy D:\ E:\ /mov /s /minage:30
Don't waste your time on trying to re-invent robocopy in VBScript.

DOS Batch file to move 2000 files every 10 minutes

Is it possible to create a DOS script that will move 2000 files to another folder every 10 minutes?
For example:
C:\MyFolder\
Every 10 minutes move 2000 files to C:\MyNewFolder\
Thank you!
I would use something like xcopy as recommended, however I would use the date flag to specify only copying new files. Just omit the date and it will copy only newer files.
/C Continues copying even if errors occur.
/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.
/E Copies directories and subdirectories, including empty ones.
xcopy C:\Source Z:\Destination /C /D /E
Use Schtasks.
You may want to look here: http://technet.microsoft.com/en-us/library/bb490996.aspx

batch script to find last two days from the current date

I am in a project where I need to find all files which are two days lesser than the current date. How can we achieve this using a batch script in Windows?
Appreciate your help!
I have previously misunderstood the question. Here is the updated answer.
The syntax is a little bit different for different OS.
forfiles /d +2 (Windows Server 2008)
forfiles -d+2 (Windows 2000)
In case there is no such command in your OS, here is a link for downloading the FORFILES command.
You can even specify what you want to do for those files. Type forfiles /? or forfiles -? for help.
Not sure what you want to do with the files after you have found them but you could use the ForFiles command.

Resources