Solved

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

Posted on 2011-02-15
9
934 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
ID: 34894817
0
 
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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