vbscript - move files older than 180days based on modified date keeping the original directory structure

March 16th, 2011 - 08:17 am ET by Kouliscon | Report spam
Hello All
I found a vbscript on the net and i need help to modified in order to
meet my needs since i dont know how to do it.
the script is:
SCRIPT

Dim objFSO, ofolder, objStream
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objNet = CreateObject("WScript.NetWork")
Set FSO = CreateObject("Scripting.FileSystemObject")
set outfile = fso.createtextfile("Move-Result.txt",true)
SPath = "c:\temp\"
ShowSubfolders FSO.GetFolder(spath)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
CheckFolder(subfolder)
ShowSubFolders Subfolder
Next
End Sub
'CheckFolder(objFSO.getFolder(SPath))
Sub CheckFolder(objCurrentFolder)
Dim strTempL, strTempR, strSearchL, strSearchR, objNewFolder, objFile
Const OverwriteExisting = TRUE
currDate = Date
dtmDate = Date - 180
strTargetDate = ConvDate(dtmDate)
For Each objFile In objCurrentFolder.Files
FileName = objFile
'WScript.Echo FileName
strDate = ConvDate(objFile.DateCreated)
'strDate = ConvDate(objFile.DateLastModified)
If strDate < strTargetDate Then
objFSO.MoveFile FileName, "e:\test\"
outfile.writeline filename
End If
Next
End Sub
Function ConvDate (sDate) 'Converts MM/DD/YYYY HH:MM:SS to string
YYYYMMDD
strModifyDay = day(sDate)
If len(strModifyDay) < 2 Then
strModifyDay = "0" & strModifyDay
End If
strModifyMonth = Month(sDate)
If len(strModifyMonth) < 2 Then
strModifyMonth = "0" & strModifyMonth
End If
strModifyYear = Year(sDate)
ConvDate = strModifyYear & strModifyMonth & strModifyDay
End Function
END OF
SCRIPT-

the thing is that i want help to the following:

1) to check the files in the folders and subfolders of the location c:
\temp and based on the MODIFIED DATE to move them to the location e:
\test

2) To keep the same exact directory structure in the new location e:
\test

3) to have the ability to place somewere *.* to select all files from
c:\temp or to put *.xls and to find and move only the .xls files that
havents been used for 180 days with the same directory structure to e:
\test.

Since i want to deploy this script with GPO i would like to replace
the e:\test to an external HDD with the variable of the username. I
intent to do this per user.

Any help will be appreciated.

thx
email Follow the discussionReplies 6 repliesReplies Make a reply

Replies

#1 Kouliscon
March 16th, 2011 - 09:00 am ET | Report spam
On Mar 16, 4:49 pm, "Mayayana" wrote:
You can download the help file here:http://www.microsoft.com/downloads/...x?FamilyId592C48-207...

Pretty much everything you want to do is included
in the methods of the FileSystemObject object.


| Hello All
| I found  a vbscript on the net and i need help to modified in order to
| meet my needs since i dont know how to do it.
| the script is:
| --BEGIN OF
| SCRIPT
|
| Dim objFSO, ofolder, objStream
| Set objShell = CreateObject("WScript.Shell")
| Set objFSO = CreateObject("scripting.filesystemobject")
| Set objNet = CreateObject("WScript.NetWork")
| Set FSO = CreateObject("Scripting.FileSystemObject")
| set outfile = fso.createtextfile("Move-Result.txt",true)
| SPath = "c:\temp\"
| ShowSubfolders FSO.GetFolder(spath)
| Sub ShowSubFolders(Folder)
| For Each Subfolder in Folder.SubFolders
| CheckFolder(subfolder)
| ShowSubFolders Subfolder
| Next
| End Sub
| 'CheckFolder(objFSO.getFolder(SPath))
| Sub CheckFolder(objCurrentFolder)
| Dim strTempL, strTempR, strSearchL, strSearchR, objNewFolder, objFile
| Const OverwriteExisting = TRUE
| currDate = Date
| dtmDate = Date - 180
| strTargetDate = ConvDate(dtmDate)
| For Each objFile In objCurrentFolder.Files
| FileName = objFile
| 'WScript.Echo FileName
| strDate = ConvDate(objFile.DateCreated)
| 'strDate = ConvDate(objFile.DateLastModified)
| If strDate < strTargetDate Then
| objFSO.MoveFile FileName, "e:\test\"
| outfile.writeline filename
| End If
| Next
| End Sub
| Function ConvDate (sDate) 'Converts MM/DD/YYYY HH:MM:SS to string
| YYYYMMDD
| strModifyDay = day(sDate)
| If len(strModifyDay) < 2 Then
| strModifyDay = "0" & strModifyDay
| End If
| strModifyMonth = Month(sDate)
| If len(strModifyMonth) < 2 Then
| strModifyMonth = "0" & strModifyMonth
| End If
| strModifyYear = Year(sDate)
| ConvDate = strModifyYear & strModifyMonth & strModifyDay
| End Function
| END OF
| SCRIPT-
|
| the thing is that i want help to the following:
|
| 1) to check the files in the folders and subfolders of the location c:
| \temp and based on the MODIFIED DATE to move them to the location e:
| \test
|
| 2) To keep the same exact directory structure in the new location e:
| \test
|
| 3) to have the ability to place somewere *.* to select all files from
| c:\temp or to put *.xls and to find and move only the .xls files that
| havents been used for 180 days with the same directory structure to e:
| \test.
|
| Since i want to deploy this script with GPO i would like to replace
| the e:\test to an external HDD with the variable of the username. I
| intent to do this per user.
|
| Any help will be appreciated.
|
| thx



Thx for your answer, i need help to modify the script by someone that
know... anybody?

Similar topics