Link to home
Create AccountLog in
Avatar of callawar
callawarFlag for Türkiye

asked on

VBSCRIPT Move JPEG FILES BY Modified DATE From Source Folder to Target Folder

I am looking for a vbscript that moves jpegs from one folder to a target folder by date modified (file).  The script should be able to move all jpeg files that are greater than 2-days old (M/D/Yr) to the  target folder.  The source folder is:  c:\inetpub\ftproot\  and the destination folder is:  c:\inetpub\Archived Folder.  Thanks in advance!
Avatar of Pratima
Pratima
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of callawar

ASKER

prashantd --  Thanks for the script however, no files transfer.  The command prompt window opens and closes but nothing happens.  There are no errors either.  
callawar can you try commenting "On Error Resume Next", to see if any errors are returned.

Secondly can you paste the script you have modified
Yes, I commented out the On Error Resume Next file.... no change....

Here is the file as is:

'On Error Resume Next

source_dir="c:\inetpub\ftproot\"
dest_dir="c:\inetpub\ftproot\Archived Folder\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set dir = fso.GetFolder(source_dir)
Set dirfiles = dir.Files

For Each dirfile In dirfiles
   datemoddiff=DateDiff("d",dirfile.DateLastModified,Date)

   If InStr(LCase(dirfile.Name),"*.jpg")>0 And datemoddiff >1 Then
       'WScript.Echo dirfile.Name & " - " & datemoddiff
       dirfile.Move (dest_dir)
   End If
Next
Remove *.jpg, only give the exact extension like .jpg or .jpeg.

What is the extension?  "*" is not required
OK.  I will try it.  
Thanks!  That did the trick.  I also made the mistake of having the same file in the target folder.  Once I removed them that did the trick.  

'On Error Resume Next

source_dir="c:\inetpub\ftproot\"
dest_dir="c:\inetpub\ftproot\Archived Folder\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set dir = fso.GetFolder(source_dir)
Set dirfiles = dir.Files

For Each dirfile In dirfiles
   datemoddiff=DateDiff("d",dirfile.DateLastModified,Date)

   If InStr(LCase(dirfile.Name),".jpg")>0 And datemoddiff >1 Then
       'WScript.Echo dirfile.Name & " - " & datemoddiff
       dirfile.Move (dest_dir)
   End If
Next
Excellent job!