New to scripting & having a steep learning curve in scripting this week!
The script below allows me to copy named files in a folder using a txt file, to a backup folder
Then it looks at the creation date, renames the file and puts the file into the folder of the same month, or creates it if the folder doesn't exist
It only does it for the ext of the file in the strExt = "csv"
I'd like to add other ext options to the same script.
is this possible? or do i have to have a separate script for each file ext
many thanks
Public fso
set fso = CreateObject("Scripting.FileSystemObject")
set Cfg = fspenTextFile("C:\Documents and Settings\uidb3\Desktop\ref_list.txt")
do while not Cfg.AtEndOfStream
str = RTrim(Cfg.ReadLine)
fso.CopyFile str, fso.BuildPath("C:\ga\backups",fso.GetFileName(str)), True
loop
' Rename & Move to folder or create folder if doesn't exist
strSource = "C:\ga\backups"
strExt = "csv"
strDest = "C:\ga\backups"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSource = objFSO.GetFolder(strSource)
For Each objFile in objSource.Files
strFileExt = objFSO.GetExtensionName(objFile.Path)
if LCase(strFileExt) = LCase(strExt) Then
If strFileExt <> "" Then
strFileExt = "." & strFileExt
End If
strMM = Right("0" & Month(objFile.DateCreated), 2)
strDD = Right("0" & Day(objFile.DateCreated), 2)
strYY = Right(Year(objFile.DateCreated), 2)
strYYYY = Year(objFile.DateCreated)
strNewName = Left(objFile.Name, 4) & "_" & strYYYY & strMM & strDD & strFileExt
strNewFolder = strDest & "\" & strYYYY & strMM
strNewPath = strNewFolder & "\" & strNewName
If Not objFSO.FolderExists(strNewFolder) Then
objFSO.CreateFolder(strNewFolder)
End If
'WScript.Echo "Move " & objFile.Path & " to " & strNewPath
objFSO.MoveFile objFile.Path, strNewPath
End If
Next
The script below allows me to copy named files in a folder using a txt file, to a backup folder
Then it looks at the creation date, renames the file and puts the file into the folder of the same month, or creates it if the folder doesn't exist
It only does it for the ext of the file in the strExt = "csv"
I'd like to add other ext options to the same script.
is this possible? or do i have to have a separate script for each file ext
many thanks
Public fso
set fso = CreateObject("Scripting.FileSystemObject")
set Cfg = fspenTextFile("C:\Documents and Settings\uidb3\Desktop\ref_list.txt")
do while not Cfg.AtEndOfStream
str = RTrim(Cfg.ReadLine)
fso.CopyFile str, fso.BuildPath("C:\ga\backups",fso.GetFileName(str)), True
loop
' Rename & Move to folder or create folder if doesn't exist
strSource = "C:\ga\backups"
strExt = "csv"
strDest = "C:\ga\backups"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSource = objFSO.GetFolder(strSource)
For Each objFile in objSource.Files
strFileExt = objFSO.GetExtensionName(objFile.Path)
if LCase(strFileExt) = LCase(strExt) Then
If strFileExt <> "" Then
strFileExt = "." & strFileExt
End If
strMM = Right("0" & Month(objFile.DateCreated), 2)
strDD = Right("0" & Day(objFile.DateCreated), 2)
strYY = Right(Year(objFile.DateCreated), 2)
strYYYY = Year(objFile.DateCreated)
strNewName = Left(objFile.Name, 4) & "_" & strYYYY & strMM & strDD & strFileExt
strNewFolder = strDest & "\" & strYYYY & strMM
strNewPath = strNewFolder & "\" & strNewName
If Not objFSO.FolderExists(strNewFolder) Then
objFSO.CreateFolder(strNewFolder)
End If
'WScript.Echo "Move " & objFile.Path & " to " & strNewPath
objFSO.MoveFile objFile.Path, strNewPath
End If
Next