|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBScript - Copy files with certain date creation
Hello,
can anyone help me to create script file for copying files for last n days (last 30 days). thanks sam |
|
#2
|
|||||
|
|||||
|
Well, you've been pretty vague in what you're looking for. Here's a script that will look in a provided folder and copy all files that haven't been accessed in 30 days. Did you just want to archive them and delete the originals? This script simply creates copies. That seems a bit pointless to me.
vb Code:
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
|
#3
|
|||
|
|||
|
Copy files with certian date creation
Nilpo, sorry about the post with confusion and I do appreciated that you took time to reply my post. I have one folder which collecting data files every day. Everyday 2 or some case 4 files created. What i am looking for to copy last 30 days files. For last 30 days, there could be 60 files or 120 files. Regardless # of files, i would like to copy by date. Please let me know if you have any question. I got one code but it is not working. This is the error, "Backup folder not exist". I do have folder backup there though.
dim BackupFilesSigDate, oFSO, oFolder, srcfolder, tgtfolder, oFile BackupFilesSigDate = date-1 srcfolder="C:\Images" tgtfolder="C:\Backup" set oFSO = CreateObject("Scripting.FileSystemObject") on error resume next set oFolder = oFSO.GetFolder(tgtfolder) if clng(oFile.DateCreated)=BackupfileSigDate-1 then wscript.echo "The Backup Folder does not exists. Operation aborted." set oFolder = nothing : set oFSO = nothing wscript.quit(1) end if set oFSO = CreateObject("Scripting.FileSystemObject") on error resume next set oFolder = oFSO.GetFolder(srcfolder) if clng(oFile.DateCreated)=BackupfileSigDate-1 then wscript.echo "The Source Folder does not exists. Operation aborted." set oFolder = nothing : set oFSO = nothing wscript.quit(2) end if on error goto 0 for each oFile in oFolder.files if oFile.DateCreated=BackupfileSigDate then oFSO.copyfile oFile.path, tgtFolder & "\" & oFile.name, true end if next set oFolder = nothing : set oFSO = nothing thanks in advance Quote: |
|
#4
|
||||
|
||||
|
Try removing the clng() functions when you're making your date comparison. VBS will handle types all on it's own. You'll notice in my example, I didn't convert any of them. I did that intentionally.
|
|
#5
|
||||
|
||||
|
I just noticed this as well...
oFSO.copyfile oFile.path, tgtFolder & "\" & oFile.name, true Take a look at the FileSystemObject's BuildPath function. Although, that shouldn't stop this from working. |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > VBScript - Copy files with certain date creation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|