Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-18
6
Medium Priority
?
477 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 1900 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 59

Assisted Solution

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

~bp
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host 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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

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…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

916 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