Results 1 to 4 of 4
  1. #1
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

    FSO FolderExists doesn't seem to work with tmp folder?

    Interesting. Anyone else found this? I have repeated this several times and am now questioning my process. Quite confusing.

    I have a series of folders in c:\users\jp\appdata\temp\XXXX

    Specifically:
    "c:\users\jp\appdata\local\temp\dbgClean"
    "c:\users\jp\appdata\local\temp\dbgWithDebug"
    "c:\users\jp\appdata\local\temp\dbgSaveRaw "
    "c:\users\jp\appdata\local\temp\tmp_TrackProcUsage "

    Code:
    ' Author: Jack
    ' Date: 15-Jan-23
    ' ----------------------------------------------------------------
    Sub DeleteTPUSessionFiles()
              Dim fldr(3) As String
              Dim i As Long
    10        On Error Resume Next
    20        fldr(0) = "tmp_TrackProcUsage"
    30        fldr(1) = "dbgWithDebug"
    40        fldr(2) = "dbgSaveRaw"
    50        fldr(3) = "dbgClean"
    
    
              Dim fso As FileSystemObject
    60        Set fso = New FileSystemObject
    70        For i = LBound(fldr) To UBound(fldr)
    80            fso.DeleteFolder "c:\users\jp\appdata\local\temp\" & fldr(i)
    90            Debug.Print Now & " deleted  " & fldr(i)
    100       Next
              'CHECK TO MAKE SURE '
    110       For i = LBound(fldr) To UBound(fldr)
    120           Debug.Print i & " " & fldr(i) & String(15 - Len(fldr(i)), " ") & " EXISTS " _
                      & fso.FolderExists("c:\users\jp\appdata\local\temp\" & fldr(i)) & "  " & Now
    130       Next i
    End Sub
    And get the following result (regardless of where I position the "tmp_TrackProcUsage" in the array.

    Code:
    15-Jan-23 4:19:01 PM deleted  tmp_TrackProcUsage
    15-Jan-23 4:19:01 PM deleted  dbgWithDebug
    15-Jan-23 4:19:01 PM deleted  dbgSaveRaw
    15-Jan-23 4:19:01 PM deleted  dbgClean
    1 dbgWithDebug    EXISTS False  15-Jan-23 4:19:01 PM
    2 dbgSaveRaw      EXISTS False  15-Jan-23 4:19:01 PM
    3 dbgClean        EXISTS False  15-Jan-23 4:19:01 PM

    FSO FolderExists does not appear to deal with tmp_TrackProcUsage.


    It will delete the folder and contents, but does not perform the FolderExists???

    I have attached a gif file (Inside the zip) showing the process.

    I could be overlooking something basic!
    Attached Files Attached Files

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    First thing I would do is remove the 'On Error Resume Next' to see what happens....

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,857
    Give another folder an underscore character ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Thanks Dave and Paul.
    The issue was the length of the folder name. I had allowed for 15 -len(folder), but
    ?Len("tmp_TrackProcUsage")
    18

    which resulted in a negative length which errors on an Invalid Function call.

    This works now. Need to look more carefully/closely!!

    Code:
    120           Debug.Print Now & "  " & i & " " & fldr(i) & String(20 - Len(fldr(i)), " ") & " EXISTS " _
                      & fso.FolderExists("c:\users\jp\appdata\local\temp\" & fldr(i))
    Code:
    15-Jan-23 6:07:28 PM deleted  tmp_TrackProcUsage
    15-Jan-23 6:07:28 PM deleted  dbgWithDebug
    15-Jan-23 6:07:28 PM deleted  dbgSaveRaw
    15-Jan-23 6:07:28 PM deleted  dbgClean
    15-Jan-23 6:07:28 PM  0 tmp_TrackProcUsage   EXISTS False
    15-Jan-23 6:07:28 PM  1 dbgWithDebug         EXISTS False
    15-Jan-23 6:07:28 PM  2 dbgSaveRaw           EXISTS False
    15-Jan-23 6:07:28 PM  3 dbgClean             EXISTS False

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 04-14-2014, 12:37 PM
  2. Just doesn't seem to work!
    By txmmoore in forum Reports
    Replies: 9
    Last Post: 01-16-2014, 11:39 AM
  3. VBA to create PDF and folder if doesn't exist!
    By crxftw in forum Programming
    Replies: 2
    Last Post: 08-08-2011, 08:53 AM
  4. Can Grow doesn't work
    By gg80 in forum Reports
    Replies: 6
    Last Post: 05-13-2011, 07:14 PM
  5. Query doesn't work the day after
    By sithis876 in forum Queries
    Replies: 1
    Last Post: 07-13-2010, 07:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums