venkataramanaiahsr
asked on
Moving X days older files in the directory structure to another folder (win2003 R2 32 bit server)
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.Fi leSystemOb ject")
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
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.Fi
Set FileCollection = fso.GetFolder(FolderPath).
Redim aTmp(FileCollection.count - 1)
i = -1
For Each File in FileCollection
i = i + 1
aTmp(i) = File.Name
Next
GetDirContents = aTmp
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
opps - yes its a typo
/s = include sub-folders
/s = include sub-folders
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
http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx
ASKER
Thanks KCTS . robocopy did the work for me
ASKER
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