Computer Hope

Microsoft => Microsoft DOS => Topic started by: kalmazz on May 21, 2009, 01:58:05 AM

Title: copy files that created today
Post by: kalmazz on May 21, 2009, 01:58:05 AM
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.

Title: Re: copy files that created today
Post by: Hedonist on May 21, 2009, 03:05:39 AM
Are all the files in one folder or spread around the file system?
Title: Re: copy files that created today
Post by: kalmazz on May 21, 2009, 03:18:41 AM
They are in one  folder.
Title: Re: copy files that created today
Post by: Reno on May 21, 2009, 07:12:32 AM
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
next
at cmd prompt, type cscript//nologo backup.vbs
Title: Re: copy files that created today
Post by: kalmazz on May 23, 2009, 12:18:11 AM
Thanks, 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]
Title: Re: copy files that created today
Post by: Dusty on May 23, 2009, 02:31:53 AM
Code: [Select]
copy "%%d" "c:\backup\"
Have you created the destination folder?

Title: Re: copy files that created today
Post by: kalmazz on May 23, 2009, 05:24:30 AM
yes,  i have created the destination folder c:\backup
Title: Re: copy files that created today
Post by: Reno on May 23, 2009, 05:49:19 AM
my 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
)
Title: Re: copy files that created today
Post by: kalmazz on May 23, 2009, 06:30:36 AM
I tried it , but still it is same.
Date format is the problem ?


[attachment deleted by admin]
Title: Re: copy files that created today
Post by: Reno on May 23, 2009, 06:53:40 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 24h
and tell me what the result
Title: Re: copy files that created today
Post by: kalmazz on May 23, 2009, 11:37:03 PM
Thanks,
IT IS DONE  :)
Title: Re: copy files that created today
Post by: TheShadow on May 25, 2009, 07:09:15 AM
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  8)

Title: Re: copy files that created today
Post by: BC_Programmer on May 25, 2009, 12:01:41 PM
thanks for the reminder- I myself have been meaning to perform some file management. my 500GB drive is running out of space  :o
Title: Re: copy files that created today
Post by: 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 ?

 
Title: Re: copy files that created today
Post by: Reno on May 28, 2009, 12:39:10 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.
(http://img20.imageshack.us/img20/5138/screenshotipl.jpg)
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]