Search code examples
batch-fileclearcase

ClearCase label parent folders of a file


With a given file path, how to label all parent folders until the VOB level?

for example, file path: \VOB1\dir1\subdir1\moredir1\file1.xml

The following elements I want to be labelled with LABEL1:

\VOB1\dir1\subdir1\moredir1\file1.xml
\VOB1\dir1\subdir1\moredir1
\VOB1\dir1\subdir1
\VOB1\dir1

With mklabel command, easy to do:

cleartool mklabel LABEL1 \VOB1\dir1\subdir1\moredir1\file1.xml \VOB1\dir1\subdir1\moredir1 \VOB1\dir1\subdir1 \VOB1\dir1

However, I want the paths to be calculated intelligently.

The parameter of mklabel -rec don't suit this purpose because the top parent folder may containt lots of other files/dirs.

Any ideas?


Solution

  • @echo off
    setlocal EnableDelayedExpansion
    
    set "filePath=\VOB1\dir1\subdir1\moredir1\file1.xml"
    set "wantedParent=VOB1"
    
    set "thisPath="
    set "labelPaths="
    set "labelThisPath="
    if "%filePath:~0,1%" equ "\" set "filePath=%filePath:~1%"
    for %%a in ("%filePath:\=" "%") do (
       set "thisPath=!thisPath!\%%~a"
       if defined labelThisPath (
          set "labelPaths=!thisPath! !labelPaths!"
       ) else if "%%~a" equ "%wantedParent%" (
          set "labelThisPath=true"
       )
    )
    
    ECHO cleartool mklabel %labelPaths%
    

    Output:

    cleartool mklabel \VOB1\dir1\subdir1\moredir1\file1.xml \VOB1\dir1\subdir1\moredir1 \VOB1\dir1\subdir1 \VOB1\dir1