Answer the question
In order to leave comments, you need to log in
How to properly delete a folder after unzipping?
The program unzips the archive into a directory called "arch_Path" in the same directory, then a series of actions with files takes place, after which you need to delete the directory, but sometimes it happens that the directory cannot be deleted because it is "in use" or the file is used though the program no longer works with it (it), how can I make sure that this directory is always deleted?
sample code if needed
"github.com/mholt/archiver"
...
archPath := filepath.Join(filepath.Dir(pathToArch), "arch_Path")
archiver.Unarchive(pathToArch, arch_Path)
...
defer func() {
err := os.RemoveAll(tempPath)
if err != nil {
log.Println(err)
}
}()
Answer the question
In order to leave comments, you need to log in
1) Find out what program is blocking your files (unlocker, for example)
2.1) If it is a program you wrote, then find places where read / write operations are not closed
2.2) If this is a foreign program, then try to close it through taskkill (or tell the user so that it closes itself)
2.3) If this is your program and you are trying to delete it, then this is done like this:
https://www.codeproject.com/Articles/31454/How-To-...
3) You can unpack to the Temp folder and delete it :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question