Results 1 to 4 of 4

Thread: Problem Deleting Files with VBA

  1. #1
    I could stop if I wanted to
    Join Date
    2015-09
    Posts
    420
    Login to Give a bone
    0

    Exclamation Problem Deleting Files with VBA

    Hello AUGI Members:

    I have a VBA routine that looks for a "plt" file in a folder and if the file exists deletes that file. A sample of the code is as follows:


    Code:
    '''''''''
         For i = 0 To lstSelectDwgs.ListCount - 1
            
            If Not bTestEnv Then
                Application.Documents.Open CurPath & lstSelectDwgs.List(i)
            End If
            
    ''''''''''Get the tabl Name from CAD
            strCTAB = ThisDrawing.GetVariable("CTAB")
            
            iFileLen = 0
            sPLTFN = ""
            strDwgName = CurPath & lstSelectDwgs.List(i)
            intDwgLen = Len(strDwgName)
            
            strActiveDwg = Left(strDwgName, intDwgLen - 4)
                 
            sPLTFN = Dir(strActiveDwg & "-" & strCTAB & ".plt")
            If Len(sPLTFN) > 0 Then
                sTempFile = FileLen(sPLTFN)
            Else
                sTempFile = ""
            End If
            
    ''''''''''If the plt file exist delete it
            If sTempFile > "" Then
                Kill (CurPath & sPLTFN)
            End If
    This segment of code runs fine in AutoCAD 2005 on a Windows 2000 Pro system but has a problem in AutoCAD 2006 on a Windows XP Pro system. If the "plt" file already exists the routine just stops at this segment of code. If I delete the "plt" file first and then run the routine, it works fine.

    There appears to be some type of difficulty with this section of code.........can anyone please assist me and use your expertise to help identify the problem.

    Any assistance would be appreciated....!

    Regards,
    Vince
    Last edited by vferrara; 2006-03-15 at 03:39 PM.

  2. #2
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: Problem Deleting Files with VBA

    Not sure why you do this:
    Code:
            sPLTFN = Dir(strActiveDwg & "-" & strCTAB & ".plt")
            If Len(sPLTFN) > 0 Then
                sTempFile = FileLen(sPLTFN)
            Else
                sTempFile = ""
            End If
            
    ''''''''''If the plt file exist delete it
            If sTempFile > "" Then
                Kill (CurPath & sPLTFN)
    when all you need is this:
    Code:
            sPLTFN = Dir(strActiveDwg & "-" & strCTAB & ".plt")
            
    ''''''''''If the plt file exist delete it
            If sPLTFN <> "" Then
                Kill (curpath & sPLTFN)
            End If
    which works for me with XP Pro.

    HTH,
    Jeff

  3. #3
    I could stop if I wanted to
    Join Date
    2015-09
    Posts
    420
    Login to Give a bone
    0

    Default Re: Problem Deleting Files with VBA

    Jeff:

    Thank you for your help and quick response...!

    I substituted your code into the body of the VBA program and it appears to work fine. I will do more testing to make sure it functions for all AutoCAD users with difficulty.

    Do you have any idea why this would function OK in AutoCAD 2005 and not in AutoCAD 2006.....??.....I would like to understand the reasoning for your change so I can possibly avoid future problems......!!!

    Thanks again for you expert assistance.

    Regards,
    Vince

  4. #4
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: Problem Deleting Files with VBA

    My logic stems from how Dir() works......if nothing is found, a zero length string ("") is returned. So removing the redundant checks just seemd too logical to me....

    As to WHY it worked on one setup and not another, I don't see any reason at all. But if you step through the code in 2006 and watch what values get returned it may help you to determine why.

    Jeff

Similar Threads

  1. Deleting imported DWG files
    By david.delcher in forum Revit Architecture - General
    Replies: 7
    Last Post: 2017-05-16, 04:32 AM
  2. .ned and .nwf - deleting files
    By ev.dysart280615 in forum NavisWorks - General
    Replies: 1
    Last Post: 2011-09-13, 05:22 PM
  3. Deleting ctb files
    By rbczarnota in forum AutoCAD Plotting
    Replies: 2
    Last Post: 2007-08-02, 06:15 PM
  4. Deleting Temp Files
    By rjcrowther in forum Revit - In Practice
    Replies: 3
    Last Post: 2007-05-29, 11:01 PM
  5. Deleting sheet set files?
    By chrise.68617 in forum AutoCAD Sheet Set Manager
    Replies: 4
    Last Post: 2004-11-05, 12:05 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
  •