View Full Version : Help with renaming part of file
NotreDave
05-30-2019, 11:15 AM
All,
Good afternoon. I have hundreds of pdf files with "Model (1)" as part of filename that I would like stripped off, i.e. Y-45E-0372 Model (1).pdf I have tried following code but to no avail (Error: Expected end of statement). Would someone be so kind to take a look at code and see what is wrong? I sure would appreciate it.
Dim strFolder As String
Dim strFile As String
strFolder = "C:\Dave"
strFile = Dir(strFolder & "\*.*")
Do While Len(strFile) > 0
If InStr(strFile, "Model (1)") > 0 Then
Name strFolder & strFile As strFolder & Replace(strFile, "Model (1), "")
End If
strFile = Dir()
Loop
Thank you,
David
Artik
05-31-2019, 08:13 AM
Name strFolder & strFile As strFolder & Replace(strFile, "Model (1)", "")
Artik
NotreDave
06-03-2019, 04:03 AM
Artik,
Thank you for taking time out to look at this but I am still getting the Expected end of statement Error.
David
Hi David. If U want U could just manipulate the file string name. Maybe...
Name strFolder & strFile As strFolder & "" & LEFT(strFile,LEN(strFile)-14) & ".pdf"
Dave
Bob Phillips
06-03-2019, 03:15 PM
Dim strFolder As String
Dim strFile As String
strFolder = "C:\Dave\"
strFile = Dir(strFolder & "\*.*")
Do While Len(strFile) > 0
If InStr(strFile, "Model (1)") > 0 Then
Name strFolder & strFile As strFolder & Replace(strFile, " Model (1)", "")
End If
strFile = Dir()
Loop
NotreDave
06-04-2019, 03:52 AM
Good morning all,
I appreciate everyone's input so far but I still can't get this to work. If someone would be so kind to create a folder called Dave in C: and and copy attached .pdf files in zip to Dave directory and use Rename.bak in zip file (change ext. to vbs) or you can view Rename.bak code using notepad. I am not sure if I should be posting the files or not. If I shouldn't, I apologize. I am also attaching screen shot of error.
Thank you much,
David
Bob Phillips
06-07-2019, 03:02 PM
What exactly is not working? I tried it and it seemed to work fine.
Paul_Hossler
06-08-2019, 07:39 PM
Are you using VBA or Windows Scripting Host?
It looks like you're using WSH (the .VBS), but the statements are VBA so I'm not surprised it isn't working
You were also missing some path seperators
If you want to use WSH, then use the FileSystemObject and the .Files collection
Some thing like this
Dim strFolder
Dim strFile
dim oFSO, oFiles, oFile
strFolder = "C:\Users\Daddy\Downloads\test\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oFile in oFSO.GetFolder(strFolder).Files
strFile = oFile.Name
If InStr(strFile, "Model (1)") > 0 Then
oFSO.MoveFile strFolder & strFile, strFolder & Replace(strFile, " Model (1)", "")
End If
Next
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.