J
Joanie Brows
Guest
I have a program that has multiple inputs that all require the unzipping of .zip files to access files that are needed for processing. I was able to find a way to unzip then using Shell32. Every file that gets unzipped causes a temporary folder to be created in my documents and settings\username\local setting\temp
The problem is, these files are numbered and they range from 1 - 99. For example, the first folder is named
Temporary Directory 1 for temp.zip
After the 99th folder is created, I get an error telling me that the file already exists and the program crashes.
I need to be able to delete all these folders but cant seem to figure out how to do it. I have been able to set it up to delete the first folder, thinking that since the first one is gone the second would automatically be named 1 as well and I could delete it but it doesnt work that way, the second is still named Temporary Directory 2 for temp.zip and all files after that follow suit, being numbered 3, 4, 5 and so on.
The code below works, but only to delete one folder. How can I edit it to somehow loop and increment the number in the middle of the folder name so that it will delete all temp folders from 1 - 99? Ive tried multiple ways but cant seem to get the syntax correct.
Private Sub CleanUpTemporaryZipFiles()
THESE FILES TO BE DELETED CAN BE FOUND IN "C:\Documents and Settings(your user account)\Local Settings\Temp".
Dim StrTemporaryDirectory As String = ""
Get the Temporary folder directory
StrTemporaryDirectory = Environment.GetEnvironmentVariable("TEMP")
If Directory.Exists(StrTemporaryDirectory & _
"\Temporary Directory 1 for temp.zip") Then
Dim directory As String = StrTemporaryDirectory & _
"\Temporary Directory 1 for temp.zip"
Dim dirInfo As New DirectoryInfo(Directory)
Loop on all the files
For Each f In IO.Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories)
Change the the file attribute to not read only so that it will not get an error deleting the file
File.SetAttributes(f.ToString, File.GetAttributes(f.ToString) _
Xor FileAttributes.ReadOnly Or FileAttributes.Hidden)
Delete the file
File.Delete(f)
Next
If System.IO.Directory.Exists(My.Computer.FileSystem.SpecialDirectories.Temp & _
"\Temporary Directory 1 for temp.zip") Then
System.IO.Directory.Delete(My.Computer.FileSystem.SpecialDirectories.Temp & _
"\Temporary Directory 1 for temp.zip")
End If
End If
End Sub
TIA!!
Joanie
-Joni
Continue reading...
The problem is, these files are numbered and they range from 1 - 99. For example, the first folder is named
Temporary Directory 1 for temp.zip
After the 99th folder is created, I get an error telling me that the file already exists and the program crashes.
I need to be able to delete all these folders but cant seem to figure out how to do it. I have been able to set it up to delete the first folder, thinking that since the first one is gone the second would automatically be named 1 as well and I could delete it but it doesnt work that way, the second is still named Temporary Directory 2 for temp.zip and all files after that follow suit, being numbered 3, 4, 5 and so on.
The code below works, but only to delete one folder. How can I edit it to somehow loop and increment the number in the middle of the folder name so that it will delete all temp folders from 1 - 99? Ive tried multiple ways but cant seem to get the syntax correct.
Private Sub CleanUpTemporaryZipFiles()
THESE FILES TO BE DELETED CAN BE FOUND IN "C:\Documents and Settings(your user account)\Local Settings\Temp".
Dim StrTemporaryDirectory As String = ""
Get the Temporary folder directory
StrTemporaryDirectory = Environment.GetEnvironmentVariable("TEMP")
If Directory.Exists(StrTemporaryDirectory & _
"\Temporary Directory 1 for temp.zip") Then
Dim directory As String = StrTemporaryDirectory & _
"\Temporary Directory 1 for temp.zip"
Dim dirInfo As New DirectoryInfo(Directory)
Loop on all the files
For Each f In IO.Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories)
Change the the file attribute to not read only so that it will not get an error deleting the file
File.SetAttributes(f.ToString, File.GetAttributes(f.ToString) _
Xor FileAttributes.ReadOnly Or FileAttributes.Hidden)
Delete the file
File.Delete(f)
Next
If System.IO.Directory.Exists(My.Computer.FileSystem.SpecialDirectories.Temp & _
"\Temporary Directory 1 for temp.zip") Then
System.IO.Directory.Delete(My.Computer.FileSystem.SpecialDirectories.Temp & _
"\Temporary Directory 1 for temp.zip")
End If
End If
End Sub
TIA!!
Joanie
-Joni
Continue reading...