Hi friends,
There are a few places in my App that let as user "attach" a PDF to a specific record. The app creates a directory for the pdf if a matching directory doesn't already exist. Then it copies the selected file and writes a record to the DB.
The user can also delete an "attachment". If the document the user deletes is the only document in the directory, I'd like to delete the directory too. The only thing I can think of is to go ahead and try to remove the directory after each attachment is deleted, trusting that RemoveDirectory () will fail if there are still files in the directory.
li_filenum = RemoveDirectory ( ls_path )
If li_filenum = 1 then
MessageBox("Remove directory succeeded", &
+ "This was the last file in directory: " &
+ ls_path +"~r~nDirectory was removed successfully.")
end if
I'm not sure I even need the MessageBox. If the user adds another file after deleting the last one, the directory will automagically be created again.
Just wondering if there's a smarter way to do this.
~~~Tracy
In the App's open event, I get the current directory and save that in a global variable. In some cases, I need the app's directory to create temporary directories and files, and to update the app.ini file.
Long story short, the CurrentDirectory() would never be the same as the directory I want to delete, and if the RemoveDirectory() fails for that reason, it doesn't really matter.