Solved

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

Posted on 2011-02-15
9
939 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

627 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