Below is a very simple code for listing files in a specified folder. It works as expected. However, when I provide one of the backup folders of this folder, it throws invalid path (backup folder path copied from win explorer window).
E.g.: Set objFolder = objFSO.GetFolder("D:\Test")** 'works well Set objFolder = objFSO.GetFolder("D:\Test (2015.2.12 3:12 PM)") 'not work. this is a previous/backup version of folder test created by Win7
Is there a way to list backup folder files with VBA in Excel?
Sub Example1()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("D:\Test")
'Set objFolder = objFSO.GetFolder("D:\Test (2015.2.12 3:12PM)") throws error
i = 1
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'print file name
Cells(i + 1, 1) = objFile.Name
'print file path
Cells(i + 1, 2) = objFile.Path
i = i + 1
Next objFile
End Sub
How backup folders look like:
When I copy the path and paste it, some ? chars appear in the brackets: \localhost\C$\Users\IBALLA1\Downloads (?Friday, ?April ?17, ?2015, ??9:05 AM)