Ownership of Files and Folders

So I try to intergrate a Button on my Toolbar to take Ownership of selected files and folders.
I tried several scripts e.g. {sourcepath$} in place of {filepath$}, but the following Button works so far the best.
Unfortunately this works only with files not folders too.

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>Take Ownership</label> <tip>Take Ownership</tip> <icon1>C:\Windows\regedit.exe,0</icon1> <function type="normal"> <instruction>@confirm Take Ownership?|Yes|No</instruction> <instruction>@runmode hide</instruction> <instruction>@admin</instruction> <instruction>takeown /f {filepath$} /r /d Y</instruction> <instruction>icacls {filepath$} /grant administrators:F /t</instruction> </function> </button>

The main problem is probably the passing of the file sequence to the command line console.
I hope there is a way to realize this Button.

Sorry, for my bad English.

I'm not 100% sure how takeown and icacls work as I've only used them in passing, but from looking at their command-line help and the arguments you are passing to them:

  • You're passing the /r argument to takeown; that tells it to "operate on files in [the] specified directory and all subdirectories."

  • You're passing the /t argument to icacls; that tells it to operate "on all matching files/directories below the directories specified."

So I'm guessing that either or both of the tools expects a directory when run in that way and will ignore any filenames passed to it.

Thank you for your first answer.

The Problem is not so much in the takeown or icacls commands, I have modified them accordingly.

I need one single Opus control sequence for passing both file and folder paths to takeown respectively icacls.
And how I tell Opus to use one takeown/icacls argument set for files and another argument set for folders and if posible in one single button.

I have finished the planed Button.
Now it works with files and folders.

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>Take Ownership</label> <tip>Take Ownership for selected files and folders</tip> <icon1>C:\Windows\regedit.exe,0</icon1> <function type="normal"> <instruction>@confirm Take Ownership?|Yes|No</instruction> <instruction>@runmode hide</instruction> <instruction>@admin</instruction> <instruction>takeown /f {file} /r /a</instruction> <instruction>icacls {file} /grant administrators:F /t</instruction> </function> </button>