In .bat
files for Windows's cmd.exe, recursively taking ownership of a folder's content goes
takeown /f foldername /r /d Y >nul: 2>&1
Problem is, it works only if in the current locale the word for Yes starts with the letter Y
. E.g. it fails in French, which uses Oui, thus requires O
.
Any workaround?
You can use the
COPY
command to determine the "yes" response used by the machine.The
%yes%
value will be the entire word, not just the first letter. I think that will work just fine. But if I am wrong, you can simply use%yes:~0,1%
instead.Update As fgrieu points out in his comment, the above will fail if the script path includes
(
. Failure due to other special characters could be fixed by ditching the outer double quotes and escaping the redirection. But the(
is problematic.Here is an alternate strategy that works as long as
%temp%
points to a valid folder that the user has write privileges. It creates a file with a name known not to cause problems. If the file already exists in%temp%
then it is undisturbed.I suppose there is no guarantee that COPY and TAKEOWN use the same yes response, but I would be shocked if they don't.