Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Scrit to delete a subfolder with spaces in the name

$
0
0

I am trying to write a script to delete a folder and all of its subfolders.  My problem is that the folder has spaces in the name and I am getting a path not found error when i try and use either the .Delete method or the FSO.DeleteFolder method.  any suggestions on hwo to get past this/ I have tried using " around the file name no luck.  Code listed below

OptionExplicit
'on error resume next
    DIM ext
    Dim sCutOffDate
    Dim sCutOffDate2
    Dim sdelit
    Dim oFSO
    Dim sDirectoryPath
    Dim oFolder
    Dim oFileCollection
    Dim oFile
    Dim iDaysOld
    Dim iDaysOld2
    Dim JMDfilname
    Dim JMDlogfile
    Dim JMDfolder2delete
    Const ForWriting = 2

'CLEAN UP LOG FILES
'Customize values here to fit your needs
    iDaysOld = 3
        sCutOffDate = DateValue(Now() - iDaysOld)
    iDaysOld2 = 14
        sCutOffDate2 = DateValue(Now() - iDaysOld2)
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set JMDlogfile = oFSO.OpenTextFile("C:\tasks\cleandblog.txt", ForWriting, True)
    JMDlogfile.WriteLine("Cut off date: " & sCutOffDate)

'!== idera FULL ================================================================================
    JMDlogfile.WriteLine("======IDERA prod=======")
    sDirectoryPath = "y:\something"
    set oFolder = oFSO.GetFolder(sDirectoryPath)
    set oFileCollection = oFolder.SubFolders
'Walk through each sub folder in this folder collection. 
'If it is older than (3) days, then delete it.
    Foreach oFilein oFileCollection
        JMDfilname = Left(UCase(oFile.Name),17)
        If (DateValue(oFile.DateLastModified) < sCutOffDate) AND (JMDfilname="PRODUCTION - FULL") Then
           JMDlogfile.WriteLine(oFile.Name)
           JMDfolder2delete = Chr(34) & "y:\something\" & oFile.Name & Chr(34)
MsgBox(JMDfolder2delete)
'           oFSO.DeleteFolder JMDfolder2delete, True
oFile.Delete(True)
        EndIf
    Next
'           
'Clean up
    JMDlogfile.Close
    Set oFSO = Nothing
    Set oFolder = Nothing
    Set oFileCollection = Nothing
    Set oFile = Nothing


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>