Having problems deleting with script

I have a javascript that searches folders and deletes files with specific names. It will delete files in the "root" directory but not the subfolder. I don't get any errors. the files just don't get deleted. I have tried selecting the subfolder making it the "root" and the files still don't get deleted.

At first, I tried cmd.Runcommand("Delete Recycle " + item); but that didn't work so then I tried cmd.Runcommand("Delete Force Recycle " + item); but that still doesn't work. I also tried removing Recycle.

I don't understand what is going on. I can manually hit the delete key with no errors.

Edit: in case depth matters, the directories are 6 deep because they are in the path of the downloads folder

Edit: depth isn't the problem. I moved the project to a different drive and it still won't delete from the subfolders.

As a work around I am using cmd.Runcommand("Copy FORCE MOVE"); then I am manually deleting the files in temp folder.

If you're adding the filepath to the command, you'll want to put quotes around it in case it contains spaces.

But that's also not the best way to do things for most commands. Use cmd.ClearFiles to ensure nothing is selected in the command object, then call cmd.AddFile to add each file you want to delete, then run the command without any paths on the command-line (e.g. just cmd.RunCommand("Delete Recycle")). It will act on the files you added with AddFile, like the same thing run from a simple non-script button would act on the selected files.

1 Like

it's whatever the Item object contains https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Item.htm

Yes, if you add an Item object to a string, it'll turn into the path string of the file/folder it represents. You need quotes around that string, but would be better off not using it at all and doing what I suggested above.

I will try your approach tommmorrow thanks.