2

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:

enter image description here enter image description here enter image description here

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)

Istvan
  • 73
  • 12

1 Answers1

0

You can't use colons in file names or folders names. The : in the time you have in a folder name can't be create and can't already be there. I don't know if that's a typo in your question or not though.

Sobigen
  • 2,038
  • 15
  • 23
  • No, this is the format Win7 creates the backups. Unfortunately I have no mean to change this. Backup folder names will contain colon. Is there a way to normalize and refer to the backup folder? Thank you – Istvan Apr 24 '15 at 20:29
  • Beyond me now. I think the colon is your issue still but I don't know how to fix it. Is is possible it's another character that looks like a colon but is actually something else? See the 2nd and 3rd answer here: http://stackoverflow.com/questions/10386344/how-to-get-a-file-in-windows-with-a-colon-in-the-filename – Sobigen Apr 24 '15 at 20:59
  • I uploaded some screenshots. any char it is in the brackets, the script cannot list that folde's files – Istvan Apr 25 '15 at 13:47