Delete Directory

I ran across an iteresting issue.  When I use the Delete Directory, this works fine with any conditions to the local machine.  What I am seeing in some of the projects I have is this.

 

I have many variables established that make up a location to where the files will reside on a UNC share location.  The have UNC location, Product Name Product Date.

What we have is a location where others are testing from. So we have to update this location with the latest project. 

Issue:  If I use the examples as stated with the delete directory, it fails to delete the folder.  We do this to trigger the date time on the folder.

What I see if if I take the above string and set it to a variable, then the Delete Directory works fine.   Not sure if others have seen this but thought I would share this information.

 

Hi Dennis,

Thanks for your post, sorry to hear you’re having problems. Delete Directory on a UNC path seems to work fine for me at the moment.

There should be no actual difference between using a variable, and typing the current variable value into the directory field. Are you sure all of the options were set the same on both actions? Also, are you sure there weren’t any errors like double-backslashes in path names, etc?

The forum software unfortunately destroyed the formatting on your specific UNC path, so I can’t comment on that.

Regards,

Angus

The error we are seeing is Directory not empty.  But when we use a full variable to that location it deletes fine on a UNC.  I do not see the issue on the local drive.

 

Hi Dennis,

I’m still not able to reproduce this, sorry. If you turn on the “Log Each Deleted File and Directory” option, what output do you see in the log?

Are the other settings on the action absolutely identical? Is it possible that one or more of the files on the UNC share are shared read-only? (“Delete Read-Only Directories” won’t work on UNC paths if the remote computer will not grant access to the file.)

Regards,

Angus

I think it has to do with permission.  The UNC path that we are updating is were people "EVERYONE" has List Read & Execute.  I noticed that some time it worked fine and other time it does not.  With a Variable that combines all the path variables it works fine. Not sure why

Here is the string I am doing

_RootNetworkBuildLoc = Network Share

ProductName = Assigned variable

ProductVersionSpeedy = Variable set from a property set  which is "Major""Minor""Build" version numbers

      %_RootNetworkBuildLoc%\MediaReleaseTest\%ProductName%%ProductVersionSpeedy%\%ProductName%

Now if I paste that in a Delete Directory with All logging. It fails part of the time.  It is not a failure all the time.   But if I set a New Variable to the listing above and Delete Directory this way, it works all the time.

Again I think it is dealing with permissional items to this folder.  I have been running successfully with setting a variable for the past week with the variable.

Dennis

 

Hi Dennis,

The first thing the Delete Directory action does is calls the ExpandExpression function on the name of the directory, to expand all variable references, and it uses that expanded value from there on. So there really shouldn’t be any difference in behaviour based on what you type into the directory field.

I’d suggest that there’s some kind of difference in the two paths, maybe a backslash or something? Or the variable values are expanding at a slightly different time?

Regards,

Angus

Thanks for the response, I am currently in a major migration into finalbuilder. Once I get done I will look to see if the variable contains no "\" on the end!

 

Dennis

 

I ran into an issue again with deleting directories with variables.  Here is what I have found.

I have my finalbuilder job create and robocopy the directory to the unc location. 

Then if it runs again it will delete the directory and copies again. 

If I try to delete to where I robocopy and it exist I get a delete failure stating that the directory is not empty

What I do is set a variable

         %_RootNetworkBuildLoc%\MediaRelease\CustAppFwork%ProductVersionSpeedy%\%ProductName%

Now if i delete it to this variable without "\"  it will intermittently work.

if I change the delete to %_RootNetworkBuildLoc%\MediaRelease\CustAppFwork%ProductVersionSpeedy%

This works all the time.

Attached is my project  IT is in the Action list Deploy

 

 

AGI_Custom_Application_Framework.fbz5 (47.099 KB)

Hi Dennis,

Thanks for the post. I’m afraid that I’m not following what’s going here.

I see that you have the “Log deleted files and directories” option enabled. If you can look at the action output from the FinalBuilder log, it should show you the full expanded pathname for each delete, and some progress information for recursive deletes. This is where I would suggest looking for clues as to why one pathname works and not the other.

To see this information quickly, go to Build History, click on the log you want to view, then right-click the “Delete Directory” action on the action list and choose “Filter Log by Action.”

This should let you work out what’s going on - I can’t reproduce the problem here because (obviously) I don’t have values for all of the dependent variables, or any of your files.

Regards,


Angus

Angus,

Basically I have issues if there are NO files in the directory and use variables but if it ends with a hardcoded value it seems to delete fine. I will look into the logging items in a while.

What I am trying to do is what I have done in the past with a script. Here is the code: I am trying to perform this same function within Finalbuilder.

I might be missing something, but the key item of concern is the subfolder count and File count!

with what I have in finalbuilder 5. I Tried with the folder iterator. recursively and then I want to delete directories if count above are 0. else I want to peform a compair on the modified date of the last folder to see if I can remove it. then check the parent and peform the action again to see if the parent folder can safely be removed. I want to perform this back to the starting folder!

Basically a cleanup Script with a date check on each folder!

'--------------------------------------------------------------------
'FindEmptyFolders - Build list of folders
'--------------------------------------------------------------------
Sub FindEmptyFolders(CompDestFolder)
On Error Resume Next
message =VBCRLF &"Finding Empty Folders: " & CompDestFolder & “.”
n=writeafile(logfile,message)
If (oFileSystem.GetFolder(CompDestFolder).SubFolders.Count = 0) AND (oFileSystem.GetFolder(CompDestFolder).Files.Count = 0) Then
EmptyFolders(x) = CompDestFolder
x = x + 1
End If

For Each Folder In oFileSystem.GetFolder(CompDestFolder).Subfolders
FindEmptyFolders(Folder.Path)
Next

Call SetMessageValueNothing()

End Sub 'FindEmptyFolders

'--------------------------------------------------------------------
'DeleteEmptyFolders - Build list of folders
'--------------------------------------------------------------------
Sub DeleteEmptyFolders()
On Error Resume Next
Do
For y = 0 to x - 1
message=VBCRLF &"Deleting Empty Folders: " & EmptyFolders(y) & “.”
n=writeafile(logfile,message)
DeleteFolders (EmptyFolders(y)): CheckError (“Delete Folder: " & EmptyFolders(y) & " Failed.”)
Next
x = 0
FindEmptyFolders(CompDestFolderCln)
Loop While x > 0

Call SetMessageValueNothing()

End Sub 'DeleteEmptyFolders