0

How to deal with file path with space? I tried use %20 as space but it doesn't work.

Set fso = CreateObject("Scripting.FileSystemObject")
FolderPath="C:\My folder path\Target folder"    
Set myLog = fso.OpenTextFile(deleteLogFile, 2, True)                                                                            

GetRecentFile fso.GetFolder(FolderPath) '<-- I am getting error here                                                                                
DeleteFiles fso.GetFolder(FolderPath)   '<-- I am getting error here                                                                                

Function GetRecentFile(srcFolder)                                                         
  Set GetRecentFile = Nothing
  For Each file in fso.GetFolder(srcFolder).Files
    If GetRecentFile is Nothing Then
      Set GetRecentFile = file
    ElseIf file.DateLastModified > GetRecentFile.DateLastModified Then
      Set GetRecentFile = file
    End If
  Next
  LatestDate = GetRecentFile.DateLastModified
End Function
M--
  • 25,431
  • 8
  • 61
  • 93
Icer Moto
  • 1
  • 1
  • 1
    what error do you get? – user2316116 Mar 31 '20 at 13:50
  • @Lankymart disagree. `FolderPath="C:\My folder path\Target folder"` is right; if you use tripled quotes then you get `Microsoft VBScript runtime error: Path not found` on `fso.GetFolder(FolderPath)`… The issue isn't in quoting, definitely! The OP should give a [mcve] including full error message. – JosefZ Mar 31 '20 at 16:03
  • @JosefZ you’re right, the error does suggest that is the issue though but the code doesn’t reflect it. – user692942 Mar 31 '20 at 16:29

0 Answers0