In tip 0557, we granted a user Full Control of all new files and folders that they create in a directory.

To grant a user Full Control on existing files in a folder, use:

JSIFCU UserName FullFolderPath,     where JSIFCU.bat contains:

<b>@echo off
if NOT \{%2\}<h1><a name="_goto_begin_syntax_echo_Syntax_JSIFCU_UserName_Folder_N_goto_end_begin_setlocal_set_user_1_set_folder_2_set_folder_folder_if_not_exist_folder_goto_syntax_if_i_3_">\{\} goto begin
:syntax
@echo Syntax: JSIFCU UserName Folder \[/N\]
goto end
:begin
setlocal
set user=%1
set folder=%2
set folder=%folder:"=%
if not exist "%folder%\*.*" goto syntax
if /i \{%3\}</a></h1>\{/N\} goto nok
set found=N
for /f "Tokens=*" %%i in ('net user %user%') do call :parse "%%i"
if "%found%"<h1><a name="_N_goto_syntax_nok_for_f_Tokens_i_in_dir_b_a_d_s_folder_do_call_doit_i_endlocal_goto_end_doit_CACLS_1_E_C_P_user_F_goto_end_parse_set_str_1_if_str_">"N" goto syntax
:nok
for /f "Tokens=*" %%i in ('dir /b /a-d /s "%folder%"') do call :doit "%%i"
endlocal
goto end
:doit
CACLS %1 /E /C /P %user%:F
goto end
:parse
set str=%1
if %str%</a></h1>"The command completed successfully." set found=Y
:end</b>
If you have a directory structure like:

<Drive:>\Folder\UserName1
<Drive:>\Folder\UserName2
<Drive:>\Folder\UserNameN

you can use JSIFCUAll.bat, which calls JSIFCU with the /N switch, to do them all.

JSIFCUAll.bat contains :

<b>@echo off
if NOT "%1"<h1><a name="_goto_begin_syntax_echo_Syntax_JSIFCUAll_TopFolder_goto_end_begin_setlocal_set_Folder_1_set_folder_folder_if_not_exist_folder_goto_syntax_for_f_Skip_4_Tokens_i_in_net_users_do_call_parse_i_endlocal_goto_end_parse_set_str_#_1#_set_str_str_#_set_str_str_#_if_str_">"" goto begin
:syntax
@echo Syntax: JSIFCUAll TopFolder
goto end
:begin
setlocal
set Folder=%1
set folder=%folder:"=%
if not exist "%folder%\*.*" goto syntax
for /f "Skip=4 Tokens=*" %%i in ('net users') do call :parse "%%i"
endlocal
goto end
:parse
set str=#%1#
set str=%str:#"=%
set str=%str:"#=%
if "%str%"</a></h1>"The command completed successfully." goto end
set substr=%str:~0,25%#
set substr=%substr:  =%
set substr=%substr: #=%
set substr=%substr:#=%
if "%substr%"<h1><a name="_goto_end_if_exist_folder_substr_call_JSIFCU_substr_folder_substr_N_set_substr_str_25_25_#_set_substr_substr_set_substr_substr_#_set_substr_substr_#_if_substr_">"" goto end
if exist "%folder%\%substr%\*.*" call JSIFCU "%substr%" "%folder%\%substr%" /N
set substr=%str:~25,25%#
set substr=%substr:  =%
set substr=%substr: #=%
set substr=%substr:#=%
if "%substr%"</a></h1>"" goto end
if exist "%folder%\%substr%\*.*" call JSIFCU "%substr%" "%folder%\%substr%" /N
set substr=%str:~50,25%#
set substr=%substr:  =%
set substr=%substr: #=%
set substr=%substr:#=%
if "%substr%"=="" goto end
if exist "%folder%\%substr%\*.*" call JSIFCU "%substr%" "%folder%\%substr%" /N
:end</b>
To grant a user Full Control of files that they own in a common folder, see tip 1255.