Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kill Command removing other files than what specified?

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
So here's basically what's going on:
1. I'm using the Winzip command line utility, wzunzip to extract Excel files from Zip files
2. I then want to remove the .zip file once the .xls file is in the folder.

My problem comes in when I'm using the FileDialog to specify the files, and telling it to delete the same file it just extracted from. Logically, I cannot see why it's deleting both the .zip file as well as the .xls file.

So here's a bit of the code where the issue is occurring:
Code:
    Dim fd As FileDialog
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim i As Variant
        
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblProjectPath")
    
    Set fd = FileDialog(msoFileDialogFilePicker)
    fd.AllowMultiSelect = True
    fd.Title = "Select TOC Return File(s) to process"
    fd.InitialFileName = rs.Fields("ProjectPath") & "\FilingReports\*.zip"
    fd.Show
    
    For Each i In fd.SelectedItems
        'Debug.Print i
        Debug.Print '------------------------'
        Debug.Print i
        Unzip (i) 'The bit calling the command line unzip utility to unzip the file - just telling it to extract all files to the current folder.
        Debug.Print i
        'Kill i
        'had to take out the kill bit, b/c it was deleting both the .zip and .xls files which is not desired nor expected
        If InStr(i, ".zip") Then
            Kill i 'Tried to specify only .zip files even though think I shouldn't need to, but it's still deleting .xls files
        End If
    Next i

I've tested, and I know for 100% certain the Unzip piece is working 100% correctly. So why is the Kill command removing anything that LOOKS like the same file name, apparently??

Any thoughts?

Thanks


"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
What happens if you save to a different location the unzipped file first?

 
Well, I shouldn't have to do that, but it does give me an idea. I could have a temp folder for extracting the excel files to and them move them back to where they should be afterwards, but then again, I'd rather just have it act correctly during usage. It makes me question it's usage in other scenarios as well. I could always use the FileSystemObject, but for such a simple action as deleting a file, you'd think using one function instead would be ideal.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
I'll also note that I considered trying to just have the code search for any zip files at the location, and delete them, however I'd rather stick to deleting specifically the files selected, in case some other file happen to be in the folder on one occasion, and it get accidentally deleted.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top