Solved

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

Posted on 2013-01-18
6
441 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 51

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now