@ECHO OFF
SETLOCAL
SET relroot=u:\directory
SET subdir=randomsubfoldername
::
FOR /f %%i IN (
'dir /b /ad %relroot%\%subdir% ^|findstr /b /e /v /g:textfile.txt '
) DO ECHO %relroot%\%subdir%\%%i
该命令以基本形式 ( )DIR
列出目录名称 ( ) - 即仅名称。查找不 ( ) 开头 ( ) 和结尾 ( )的行与文件文件名 ( )中的行/ad
.b
findstr
/v
/b
/e
/g:filename
使用修改后的信息,并注意到原始信息清楚地显示倒数第二个目录名称是相同的,并且选择发生在叶子上,现在提供的单个示例......
@ECHO OFF
SETLOCAL
ECHO Here is a test structure
ECHO -----------------------------
DIR /s /b /ad u:\directory
ECHO ------Here is the textfile---------
TYPE u:\directory\textfile.txt
ECHO ====Method 1==============
FOR /f %%i IN (u:\directory\textfile.txt) DO (
DIR /s /b /ad u:\directory | FINDSTR /r ".*\\%%i\\.*" | FINDSTR /v /r ".*\\%%i\\.*\\.*"
)
ECHO ====Method 2==============
FOR /f %%i IN (u:\directory\textfile.txt) DO (
FOR /f %%s IN (
'DIR /s /b /ad u:\directory ^| FINDSTR /r ".*\\%%i\\.*" ^| FINDSTR /v /r ".*\\%%i\\.*\\.*"'
) DO ECHO selected : %%s
)
ECHO ====Method 3 - to ignore ...\target\subdir that has any subdir ==============
FOR /f %%i IN (u:\directory\textfile.txt) DO (
FOR /f %%s IN (
'DIR /s /b /ad u:\directory ^| FINDSTR /r ".*\\%%i\\.*" ^| FINDSTR /v /r ".*\\%%i\\.*\\.*"'
) DO (
FOR /f %%c IN ( 'DIR /a:d %%s ^|FIND /c "<" ' ) DO IF %%c==2 ECHO SELECTED : %%s
)
)
下面是运行结果:
Here is a test structure
-----------------------------
u:\directory\another
u:\directory\yetanother
u:\directory\572
u:\directory\another\yetanother
u:\directory\another\yetanother\572
u:\directory\another\yetanother\1572
u:\directory\another\yetanother\5722
u:\directory\another\yetanother\572\wantthis
u:\directory\another\yetanother\572\andthis
u:\directory\another\yetanother\572\maywantthisidontknow
u:\directory\another\yetanother\572\572
u:\directory\another\yetanother\572\maywantthisidontknow\ignore
u:\directory\another\yetanother\1572\ignorethis
u:\directory\another\yetanother\5722\ignorethis
u:\directory\yetanother\572
u:\directory\yetanother\572\wantthis
u:\directory\572\wantthis
------Here is the textfile---------
23
753309
572
====Method 1==============
u:\directory\another\yetanother\572\wantthis
u:\directory\another\yetanother\572\andthis
u:\directory\another\yetanother\572\maywantthisidontknow
u:\directory\another\yetanother\572\572
u:\directory\yetanother\572\wantthis
u:\directory\572\wantthis
====Method 2==============
selected : u:\directory\another\yetanother\572\wantthis
selected : u:\directory\another\yetanother\572\andthis
selected : u:\directory\another\yetanother\572\maywantthisidontknow
selected : u:\directory\another\yetanother\572\572
selected : u:\directory\yetanother\572\wantthis
selected : u:\directory\572\wantthis
====Method 3 - to ignore ...\target\subdir that has any subdir ==============
SELECTED : u:\directory\another\yetanother\572\wantthis
SELECTED : u:\directory\another\yetanother\572\andthis
SELECTED : u:\directory\another\yetanother\572\572
SELECTED : u:\directory\yetanother\572\wantthis
SELECTED : u:\directory\572\wantthis
这两个FINDSTR
正则表达式结构是
FINDSTR /r ".*\\%%i\\.*"
任意数量的任意字符, \
, 目标字符串, \
, 任意数量的任意字符
FINDSTR /v /r ".*\\%%i\\.*\\.*"
任意数量的任意字符, \
, 目标字符串, \
, 任意数量的任意字符, \
, 任意数量的任意字符
但是 - /v
FINDSTR 上的意思是除了匹配的行...
我无法理解copy the sub-folder from a parent folder with a random name.
ECHO SELECTED : %%s
如果要求从该目录的父目录复制到所选目录,则在通过替换验证目标目录显示ECHO SELECTED : %%s
后
(
pushd %%s
xcopy ..\* . >nul
popd
)
>nul
抑制 xcopy报告
如果它意味着其他东西,则需要更多信息。