Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-15
9
Medium Priority
?
943 Views
Last Modified: 2012-05-11
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!
0
Comment
Question by:callawar
  • 5
  • 3
9 Comments
 
LVL 12

Accepted Solution

by:
prashanthd earned 2000 total points
ID: 34895967
Following script will move > 2days old modified .jpeg files
On Error Resume Next

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

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),".jpeg")>0 And datemoddiff >2 Then
    	'WScript.Echo dirfile.Name & " - " & datemoddiff
        dirfile.Move (dest_dir)
    End If
Next

Open in new window

0
 

Author Comment

by:callawar
ID: 34896200
prashantd --  Thanks for the script however, no files transfer.  The command prompt window opens and closes but nothing happens.  There are no errors either.  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:prashanthd
ID: 34896565
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
0
 

Author Comment

by:callawar
ID: 34896789
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
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34897121
Remove *.jpg, only give the exact extension like .jpg or .jpeg.

What is the extension?  "*" is not required
0
 

Author Comment

by:callawar
ID: 34897162
OK.  I will try it.  
0
 

Author Comment

by:callawar
ID: 34897229
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
0
 

Author Closing Comment

by:callawar
ID: 34897234
Excellent job!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question