Jump to content
Sign in to follow this  
SublimePorte

Remove and create directory

Recommended Posts

SublimePorte

Hi,

I am trying to remove a directory, and then re-create it. The directory has about 300mb of data in it, and for some reason it won't fully delete until the script finishes executing, which therefore means re-creating the directory is impossible.

If FileExists($dbpath) Then
        If Not DirRemove($dbpath, 1) Then
            WriteToLog("Could not remove database directory")
            Return
        EndIf
    EndIf
    ;Sleep(3000)
    If Not DirCreate($dbpath) Then
        WriteToLog("Could not create database directory")
        Return
    EndIf
Edited by SublimePorte

Share this post


Link to post
Share on other sites
hawky358

That should work fine. The only thing that would prevent the removal is an open file within the path.

Since it deletes when your script ends, check if your script doesn't have an open filehandle when you're trying to delete the folder.

Share this post


Link to post
Share on other sites
SublimePorte

Well there is an mssql database in the path, but some code is run to detach it beforehand.

And a further check is done to make sure no database in the path is attached.

As soon as I terminate the script, the deleted folder disappears, but so long as the script remains open, the folder will not disappear, and is unusable in explorer (and other file managers), it's like the script itself is putting a lock on the files, and doesn't release them or flsuh the delete operation until the script ends. It's very strange behaviour.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.