Z
Zachariah
I have code that renames files in a folder. Here it is:
Dim strPath As String
Dim objFSO As New Scripting.FileSystemObject
Dim objFolder
Dim objFile
Dim strOldPath As String
Dim strNewPath As String
Dim strTime As String
strPath = "C:\Out\"
objFSO = CreateObject("Scripting.FileSystemObject")
objFolder = objFSO.GetFolder(strPath)
For Each objFile In objFolder.Files
'Get time
strTime = Format _
(Microsoft.VisualBasic.Timer, "00000.00000")
strTime = Format(Today(), "yyyyMMdd") + Trim(Mid _
(strTime, 1, (InStr(strTime, ".") - 1))) + Mid _
(strTime, (InStr(strTime, ".") + 1), (Len(strTime) _
- InStr(strTime, ".") + 1))
strOldPath = strPath & objFile.Name
'strNewPath = strPath & strTime & objFile.Name
strNewPath = strPath & strTime & ".jpg"
Microsoft.VisualBasic.Rename(strOldPath, strNewPath)
Next objFile
objFile = Nothing
objFolder = Nothing
objFSO = Nothing
The line
strNewPath = strPath & strTime & ".jpg"
is causing a
An unhandled exception of type 'System.ArgumentException'
occurred in microsoft.visualbasic.dll
Additional information: Procedure call or argument is not
valid.
message. If I used the commented line above it the code
works but I'm stuck with new filenames that still
include the old file names in them. I want to eliminate
the old file names but if I take out the objFile.Name
reference the code breaks. Is there a workaround for this?
Dim strPath As String
Dim objFSO As New Scripting.FileSystemObject
Dim objFolder
Dim objFile
Dim strOldPath As String
Dim strNewPath As String
Dim strTime As String
strPath = "C:\Out\"
objFSO = CreateObject("Scripting.FileSystemObject")
objFolder = objFSO.GetFolder(strPath)
For Each objFile In objFolder.Files
'Get time
strTime = Format _
(Microsoft.VisualBasic.Timer, "00000.00000")
strTime = Format(Today(), "yyyyMMdd") + Trim(Mid _
(strTime, 1, (InStr(strTime, ".") - 1))) + Mid _
(strTime, (InStr(strTime, ".") + 1), (Len(strTime) _
- InStr(strTime, ".") + 1))
strOldPath = strPath & objFile.Name
'strNewPath = strPath & strTime & objFile.Name
strNewPath = strPath & strTime & ".jpg"
Microsoft.VisualBasic.Rename(strOldPath, strNewPath)
Next objFile
objFile = Nothing
objFolder = Nothing
objFSO = Nothing
The line
strNewPath = strPath & strTime & ".jpg"
is causing a
An unhandled exception of type 'System.ArgumentException'
occurred in microsoft.visualbasic.dll
Additional information: Procedure call or argument is not
valid.
message. If I used the commented line above it the code
works but I'm stuck with new filenames that still
include the old file names in them. I want to eliminate
the old file names but if I take out the objFile.Name
reference the code breaks. Is there a workaround for this?