|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Searching through folders/ subfolders and rename files if certain condition is met
Hi! I'm trying to rename some files/documents in a folder and its sub-folders (located in a online sharepoint), beacuse, when copying them, I get an error saying that the file name is too long. I'be been trying to use the code bellow, but it doesn't work. Could you help me, please? Code:
Sub command_button1() Const FILEPATH As String = "HYPERLINK" Const NEWPATH As String = "HYPERLINK" Dim strfile As String Dim freplace As String Dim flocation As String Dim fsuffix As String Dim propfname As String Dim fls, f With flocaion .SearchSubFolders = True .LookIn = "C:\Users\mihneion\Desktop\TEST RENAMING FILES" Set fls = GetFiles(FILEPATH) For Each f In fls Debug.Print f strfile = Dir(f) If Len(strfile) > 199 Then strfile = Left(strfile, 199) propfname = FILEPATH & strfile FileExistsbol = FileExists(propfname) If FileExistsbol Then Kill propfname End If Name FILEPATH & strfile As propfname 'fso.CopyFile(FILEPATH & propfname, NEWPATH & propfname, True) End If Next f End With End Sub Function GetFiles(path As String, Optional pattern As String = "") As Collection Dim rv As New Collection, f If Right(path, 1) <> "\" Then path = path & "\" f = Dir(path & pattern) Do While Len(f) > 0 rv.Add path & f f = Dir() 'no parameter Loop Set GetFiles = rv End Function |
#2
|
|||
|
|||
Hi
If your new filepath length is more than 218 characters then this is not allowed in Windows. Hope this helps. Tony |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to change/convert/delete txt files in folder+subfolders | NoS | Word VBA | 4 | 03-03-2016 12:10 PM |
Can a macro rename Excel files based on a cellname? | chrisd2000 | Excel Programming | 1 | 06-23-2014 06:50 PM |
Rename Files | gsrikanth | Excel Programming | 3 | 05-14-2012 03:03 AM |
Can't create subfolders in shared Contact folders | shellyrc7 | Outlook | 0 | 03-30-2012 08:18 PM |
Searching Outlook folders not working | cltaylor | Outlook | 0 | 08-31-2009 10:28 AM |