Search code examples
batch-filevariablespermissionsdirectory

Batch file folder permissions from variable


I need to change folder permissions (and the contained files) from a bat file using a variable.

something like:

icacls "%dat%"  /T /C /grant *S-1-1-0:(f)

but that does not seem to work as expected. The %dat% variable works fine as the rest of the bat works for people who do not have permission issues with the folder,

the bat file I created starts off

set root=%~dp0
ECHO DRAG YOUR T.O.P FOLDER HERE
ECHO the one With "textures" folder inside.
set /p top= Then press Enter
ECHO Drag your fallout 4 Data folder here
set /p dat= then press enter
ECHO Drag your Archive2 folder here
set /p arc= then press enter
goto :choice1

(that part works fine) It then goes to a selection of choices which also work fine.

The only issue is some people do not have permissions to modify the data folder. And the bat file needs to create folders, and move files within that folder.

I think the issue my be that:

icacls "%dat%"  /T /C /grant *S-1-1-0:(f)

is setting permissions for the contents of the data folder but not the data folder itself.

its worth noting that the bat file needs to be run from inside the data folder to eliminate variables. so whilst moving it one folder up in the directory tree could allow me to use it as is and eliminate the issues of he few. It would undoubtedly cause more issues for the many.

As it stands right now everything that NEEDS to work does work, the only issue being that I cannot seem to set folder permissions on the dat folder. And I do not really want to add an extra variable unless I have too..

(I could add a "set /p new=" section to the starting sequence, but I swear I should be able to do it without that.)

Any help welcome.

I would post the entire bat file here, but I don't see it is needed. it is just a repeating list of go to: commands which process a file individually.

(move a file to a created folder, extract that file to a second created folder. add extra files to the extracted files, recompress the extracted files to the same file name as the original, moves the new file to the original location, deletes the 2 working folders, recreates the 2 working folders with the same name, and then goes on to the next file)

All of that works fine. and I'm sure you can imagine how it is done.

-=edit=-

Just wondering if its my execution of the icals that's wrong.. would this be correct?

icacls "%dat%" /grant:r *S-1-1-0:f /T /C

or is the 1st way I am structuring it fine?


Solution

  • the answer was :

    icacls %dat% /grant:r *S-1-1-0:(OI)(CI)F /T /C
    

    ...

    ( %dat% ) being a variable directory address which was inputed earlier in the bat file.
    

    /grant:r was needed as without :r it was giving special permissions instead of setting the actual permissions. (i thought you needed /l to do that)

    /t sets the permission from the variable to all subfolders and files.
    F is Full permission. (for some reason it does not need a / 
    /c lets the thing continue running even if there were errors. 
    (OI) is Object inherit.
    (CI) is container inherit. 
    and *S-1-1-0: is the user. (that is the ID for "everyone" that way it works on any language. 
    

    "everyone" may fail on non english versions"