Solved

Moving X days older files in the directory structure to another folder  (win2003 R2 32 bit server)

Posted on 2013-01-18
6
459 Views
Last Modified: 2013-01-21
I have folder structure for user in file server as follows

Root folder a
    file1
    file 2
    file 3 ....
   Folder aa
      file 1
      file 2 .....
      Folder aaa
         file 1
         file 2 ..

 i want to browse through all the nested folders  and move  all the files older than 60days to current date  to another  drive folder ( pref in the same structure .  if it is too complicated atleaset to single folder) in the same machine .

I googled a bit and i found the following script which works fine but only  for the files in the  folder mentioned in the  path. it does not browse all the nested folders and trnasfers the files.  Can some expert  show me how to tweak   it to serve the above purpose.


Option Explicit

On Error Resume Next

Dim fso, FileSet, Path, File, DDiff, Date1, Date2, DestPath

Path = "C:\D_DATA\Files"
DestPath = "C:\Fileold\"
'DestPath must end with \
FileSet = GetDirContents(Path)

For each File in FileSet
 Set File = fso.GetFile(Path & "\" & File)
 Date1 = File.DateLastModified
 Date2 = Now()

  DDiff = Abs(DateDiff("d", Date1, Date2))

    If DDiff >= 60 Then
      If Not fso.FileExists(DestPath & File.Name) Then
        File.Move DestPath
        'wscript.echo File.Name
      Else
        wscript.echo "Unable to move file [" & File.Name & "].  A file by this name already exists in the target directory."
      End If
    End If
Next

Function GetDirContents(FolderPath)
 Dim  FileCollection, aTmp(), i
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set FileCollection = fso.GetFolder(FolderPath).Files

  Redim aTmp(FileCollection.count - 1)
  i = -1

    For Each File in FileCollection
       i = i + 1
       aTmp(i) = File.Name
    Next

  GetDirContents = aTmp
End Function
0
Comment
Question by:venkataramanaiahsr
[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
  • 3
  • 2
6 Comments
 
LVL 70

Accepted Solution

by:
KCTS earned 475 total points
ID: 38794075
Why not just use Robocopy

ROBOCOPY C:\SourceFoldern D:\DestinationFolder /move /minage:100 /s4

just replace the minage:100 with the number of days required
0
 

Author Comment

by:venkataramanaiahsr
ID: 38796456
with  /s4  robocopy threw error. with out that it just moved the files in the root folder.
It did not move the files in the subfolders.

 what is /s4 and is there any other switch which does this job.   I went thro the help doc and i could not find any switch which moves the files in the subfolders. there is a switch to copy the files in the subfolders to another with the same directory strucure
0
 
LVL 56

Assisted Solution

by:Bill Prew
Bill Prew earned 25 total points
ID: 38796463
/s4 looks like a typo to me, the correct switch should be just /s

~bp
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 70

Expert Comment

by:KCTS
ID: 38796588
opps - yes  its a typo

/s   = include sub-folders
0
 
LVL 70

Expert Comment

by:KCTS
ID: 38796593
Here is a full list of options - /s in the first entry in the second block (copy options)

http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx
0
 

Author Closing Comment

by:venkataramanaiahsr
ID: 38802263
Thanks KCTS . robocopy did the work for me
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

630 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