Solved

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

Posted on 2011-02-15
9
923 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 39

Expert Comment

by:Pratima Pharande
Comment Utility
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
Comment Utility
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
Comment Utility
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
 
LVL 12

Expert Comment

by:prashanthd
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:callawar
Comment Utility
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
Comment Utility
Remove *.jpg, only give the exact extension like .jpg or .jpeg.

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

Author Comment

by:callawar
Comment Utility
OK.  I will try it.  
0
 

Author Comment

by:callawar
Comment Utility
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
Comment Utility
Excellent job!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now