SourceFolder = "C:\FolderA\"
TargetFolder = "C:\FolderB\"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder(SourceFolder)
For Each file in objFolder.Files
strExt = objFSO.GetExtensionName(file)
OrgName = objFSO.GetBaseName(file)
NewName = Left(OrgName, Len(OrgName) - 10)
objFSO.CopyFile file, TargetFolder & NewName & "." & strExt, True 'True = overwrite target file if present
Next
Set objFSO = Nothing
Dim objFSO, strArgs, objFolder, objFile, objFile2
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set the FTP pickup Directory
strSPSFTPInbound = "c:\scripts\SPSFTPTest" ''SPS Test directory
' Set the drop directories
str850BackupFolder = "c:\scripts\backup\inbound\" '' specify folder where the backup file is copied to from SPS FTP
str850ProdFolder = "c:\scripts\prod\inbound\" '' specify folder where the file is moved for import to PRMS
' Loop the files in the SPS FTP folder
Set objFolder = objFSO.GetFolder("C:\Scripts\SPSFTPTest\")
'Make Backup of File
For each objFile in objFolder.Files
objFile.Move str850BackupFolder & objFile.Name
'Make copy of File removing the yyyymmddss
Set objFile2 = Left(objFile.Name,11)
objFile.Copy str850ProdFolder & objFile2.Name
Next
SourceFolder = "C:\FolderA\"
TargetFolder = "C:\FolderB\"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder(SourceFolder)
For Each file in objFolder.Files
If objFSO.GetExtensionName(file)="txt" Then
strExt = objFSO.GetExtensionName(file)
OrgName = objFSO.GetBaseName(file)
NewName = Left(OrgName, Len(OrgName) - 10)
objFSO.CopyFile file, TargetFolder & NewName & "." & strExt, True
End If
Next
Set objFSO = Nothing
Dim objFSO, strArgs, objFolder, objFile, objFile2
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set the FTP pickup Directory
strSPSFTPInbound = "c:\scripts\SPSFTPTest" ''SPS Test directory
' Set the drop directories
str850BackupFolder = "c:\scripts\backup\inbound\" '' specify folder where the backup file is copied to from SPS FTP
str850ProdFolder = "c:\scripts\prod\inbound\" '' specify folder where the file is moved for import to PRMS
' Loop the files in the SPS FTP folder
Set objFolder = objFSO.GetFolder("C:\Scripts\SPSFTPTest\")
'Make Backup of File
For each objFile in objFolder.Files
objFile.Move str850BackupFolder & objFile.Name
'Make copy of File removing the yyyymmddss
strFile2 = objFSO.GetBaseName(objFile)
NewFileName = Left(strFile2, Len(strFile2) - 10) & objFSO.GetExtensionName(objFile)
objFile.Copy str850ProdFolder & NewFileName
Next
Set objFSO = Nothing
For each objFile in objFolder.Files
objFile.Copy str850BackupFolder & objFile.Name
'Make copy of File removing the yyyymmddss
''If File already exists in str850ProdFolder, then open File and paste current file.
strFile2 = objFSO.GetBaseName(objFile)
NewFileName = Left(strFile2, Len(strFile2) - 14) & "." & objFSO.GetExtensionName(objFile)
If objFSO.FileExists(str850ProdFolder & NewFileName) Then
Set aFile = objFSO.OpenTextFile(str850ProdFolder & NewFileName, 8) '8=for appending
Set cFile = objFSO.OpenTextFile(objFile, 1) '1=for reading
s = cFile.ReadAll
aFile.Write s
aFile.Close
cFile.Close
Else
objFile.Copy str850ProdFolder & NewFileName
End If
Open in new window