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