Solved

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

Posted on 2013-01-18
6
454 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 54

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
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…
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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