Comparing to the worst pieces of source code I have ever written, this one is definitely under the top three.
However, after doing almost every possible batch beginner's mistake, the code below finally does what I need (considering the limitation mentioned in the code).
It will cloak all folders and files below the predefinded root folder myServerFolder
. myServerFolder
must have the following syntax including the final slash: $/myProject/myFolder/
.
If anyone has a good idea to simplify the code or has found a bug please edit it directly or let me know.
Again, thank you for your support!
@echo off
setlocal enabledelayedexpansion
REM Limitation: Folder and file names must not end with ")" nor start with "$"
set myServerFolder=$/myProject/myFolder/
REM Process Folders
for /f "Tokens=*" %%a in ('tf.exe dir %myServerFolder%') do (SET TEXT=%%a& SET SUBSTR_A=!TEXT:~-1!& SET SUBSTR_B=!TEXT:~0,1!& (IF "!SUBSTR_A!" NEQ ":" IF "!SUBSTR_A!" NEQ ")" (IF "!SUBSTR_B!" EQU "$" (set currParam=!TEXT:~1!&(tf.exe workfold /cloak "%myServerFolder%%!currParam!")))))
REM Process Files
for /f "Tokens=*" %%a in ('tf.exe dir %myServerFolder%') do (SET TEXT=%%a& SET SUBSTR_A=!TEXT:~-1!& SET SUBSTR_B=!TEXT:~0,1!& (IF "!SUBSTR_A!" NEQ ":" IF "!SUBSTR_A!" NEQ ")" (IF "!SUBSTR_B!" NEQ "$" (set currParam=!TEXT!&(tf.exe workfold /cloak "%myServerFolder%%!currParam!")))))
PAUSE