Solved

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

Posted on 2013-01-18
6
449 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
  • 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 53

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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Alert on Server memory 2 38
Clear Filter 8 61
a slight change to the code written by Brad Yundt 2 34
IDENTIFY, THEN ADD TOGETHER AND DELETE ONE, EXCEL 3 18
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

830 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