2016-01-15 55 views
1

使用给定的文件路径,如何标记所有父文件夹直到VOB级别?ClearCase标签文件的父文件夹

例如,文件路径:\ VOB1 \ DIR1 \ subdir1 \ moredir1 \ file1.xml

下列元素我想与LABEL1标记:

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

随着mklabel命令,易做:

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

但是,我想路径智能计算。

mklabel -rec的参数不适合此目的,因为顶级父文件夹可能包含许多其他文件/目录。

任何想法?

回答

1
@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% 

输出:

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

我打算将此作为一种好方法。谢谢, – dellair

0

由于没有得到父母的文件夹列表(除非cleartool lsfolder -ancestor作品)没有本土的方式,只需将“CD ..”,直到mklabel失败(这将意味着你是VOB外)

cleartool mklabel LABEL1 . || exit 
cd .. 

在bash:

while true; do cleartool mklabel LABEL1 . || exit; cd ..; done