1.

Solve : copy files that created today?

Answer»

Hi Gurus,

I want to create a batch file and put in WINXP shecdule ,

THAT COPIES THE FILES THOSE ARE CREATED ON THE DAY WHEN THE BATCHFILE IS EXECUTED TO ANOTHER LOCATION.

Are all the files in one folder or spread around the file system?They are in one folder.method 1: use xcopy /d

method 2:use for loop & dir
Code: [Select]@echo off
for /f "skip=1 TOKENS=1-3*" %%a in ('dir/a-d/tc/o-d^|find ":"') do (
if %%a==%date:~-10% (
echo %%a %%d
copy "%%d" "c:\backup\
) else goto:eof
)
method 3: use vbscript
Code: [Select]set fso=createobject("scripting.filesystemobject")
for each f in fso.getfolder(".").files
if datediff("d",f.datecreated,date())=0 then
wsh.echo f.datecreated,f
f.copy "c:\backup\"
end if
nextat cmd prompt, type cscript//nologo backup.vbsThanks, I used method 2.
But It gaves the message " The specified file cannot be found" . I have ATTACHED the screen shot.
What I need is :
Copy the ONLY THE file that created today to another folder.

[attachment deleted by admin]Code: [Select]copy "%%d" "c:\backup\"
Have you created the destination folder?

yes, i have created the destination folder c:\backupmy mistake, i didn't take account for time format "hh:mm am/pm"

updated code that support both 12h and 24h format:
Code: [Select]@echo off & setlocal
time/t|find "M" && set t=1,4* || set t=1,3*

for /f "skip=1 tokens=%t%" %%a in ('dir/a-d/tc/o-d^|find ":"') do (
if %%a==%date:~-10% (
echo %%a %%c
copy "%%c" "c:\backup\"
) else goto:eof
)I tried it , but still it is same.
Date format is the problem ?


[attachment deleted by admin]Quote from: kalmazz on May 23, 2009, 06:30:36 AM

I tried it , but still it is same.
Date format is the problem ?
no, i have take account for both date format, ddd mm/dd/yyyy or mm/dd/yyyy.

double check the code, try to copy & paste all the new code again at post#8. if your time format is 12h, it should display current time on the first line when the batch is executed.

additional check (type at cmd prompt):
Code: [Select]time/t
time/t|find "M" && (echo 12h) || echo 24hand tell me what the resultThanks,
IT IS DONE If you miss a day, you'll also miss copying some files because you're limiting your copy to just the files created "Today".

If you're using this batch file as a means of backing up critical data files, you might just want to use a BROADER criteria for the files being copied.

I use XCOPY to keep all my data files on C: backed up to D:

I just incorporated the XCOPY lines into my end of day shutdown script (batch file).

When done properly, with the correct SWITCHES, xcopy copies only files that are either new or have been updated since the last backup.
My batch file looks something like this:

Quote
@Echo off
cls
Rem Backup My Documents and all sub-folders/files.
xcopy "C:\Documents and Settings\Alex\My Documents\*.*" "D:\My Documents\" /s /y /H /R /D

Rem Back up my WordPerfect files.
xcopy "C:\MyFiles\*.*" "D:\MyFiles\" /s /y /H /R /D

Rem Back up all the files for My Web Page.
xcopy "C:\My web page\*.*" "D:\My web page\" /s /y /H /R /D

Rem Back up my email folders.
xcopy "C:\Documents and Settings\Alex\Local Settings\Application Data\Identities\{CC1A6FC7-0D07-4169-865D-56EBDD76EB8B}\Microsoft\Outlook Express\*.dbx" "D:\MyEmailFiles-Backup\" /s /y /H /R /D

Rem When the backup is done...Shutdown!

%windir%\System32\shutdown.exe -s -t 00 -f

On an average day, I may be backing up only one or two files, so the batch file runs and finishes in just a few seconds. It assures that I never shut down my PC with unsaved data files.
In this case D: is my backup hard drive.

Batch files can get really complicated or you can "KEEP IT SIMPLE".
Just add lines to accommodate any folders in your PC that contain valuable data.
That would be different for each person.

Even though I make a Ghost backup of my entire C: drive, at least once a week, my shutdown batch file assures that I keep all my data files backed up between Ghost backups.

So, don't loose your stuff to a HD crash.
Backup, Backup, Backup!!!

The Shadow

thanks for the REMINDER- I myself have been meaning to perform some file management. my 500GB drive is running out of space Thanks for your information on backups.
I have a system that copies the backup files daily with different names on a folder. Ex. C:\BACKUPS.
I need to keep only last 7 days backup files and delete the previous days' file on daily basis.
How do I do it in a batch file ?

Quote from: kalmazz on May 27, 2009, 07:59:55 AM
Thanks for your information on backups.
I have a system that copies the backup files daily with different names on a folder. Ex. C:\BACKUPS.
I need to keep only last 7 days backup files and delete the previous days' file on daily basis.
How do I do it in a batch file ?
since this question is being ask a lot from day to day, here is an example .hta script.

this is my first hta script, so the code is messy & dirty.
i couldn't get the progressbar image to work properly and showing file being copied interactively.
feel free to modify the code in notepad, it is basically a vbscript wrapped inside html code.
WARNING: use at your own risk!!! test first on testing folder

[attachment deleted by admin]


Discussion

No Comment Found