如何创建一个忽略括号内文本而仅复制其余文本的蝙蝠?
有很多这样的文件:
[2019]Text1(text2).zip
我希望我的批次仅复制text1,创建一个名称的文件夹,然后在其中移动文件。
应该这样:text1/[2019] text1(text2).zip
这是不起作用的,我不知道该如何忽略括号中的文本。
for %%F in (*.zip*.rar) do (
for /f "tokens=2* delims=%%I in ("%%~nA") do (
@mkdir "%%F" 2>nul & move "%%I" "%%J\" >nul
There are many files like this:
[2019]Text1(text2).zip
I want my batch to copy only Text1, create a folder with that name and move the file in it.
It should be like this: Text1/[2019]Text1(text2).zip
This doesn't work, and I don't know how to let it ignore text in brackets.
for %%F in (*.zip*.rar) do (
for /f "tokens=2* delims=%%I in ("%%~nA") do (
@mkdir "%%F" 2>nul & move "%%I" "%%J\" >nul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
建立源和目标目录后,请使用
pushd
将当前目录切换到源目录。在
dir/b/ad code>命令的每一行中读取
%% b
the(基本列表无目录名称(/ad Ad
)) - 选择两者 所有所有
.zip
和 使用[]()()
的定界符检查%% B
中的字符串。代码> %% t ...剩余的行向%% W
echo
line只是为了显示文件名的标记 - 每个令牌 “ ++”之间显示。在
2019
,%% T
text1,%% u
text2
,%% V
应该为空。.zip
和%% W
>是.zip
或.rar
,case-nomentive(/i
)和如果%% V
匹配一个或另一个,执行MD
创建目标目录(如果该目录已经存在,将生成一个错误消息,该消息被2> Nul
)和然后将文件移至该目录。最后,
popd
返回到原始当前目录注意
md
和移动
仅仅是echo
ed,以便您可以查看指令是否正确。要实际执行MD
和echo
您需要从这些行中删除echo
关键字。各种检查是一个合理的粗略尝试,以确保仅处理
[2019] text1(text2).zip
的文件。一个名为[2019] text1(text2)extra.zip
或[2019](text2)的文件。 [2019]] text1(text2).zip
将通过检查。您可以将
dir
filemask更改为EG。[*]*(*)。ZIP
,但即使那将通过一些不合格的文件名。移动
命令将生成1 fie(s)在洗袜子时移动
消息。您可以通过将> nul
附加到move> move
命令来抑制此消息。After establishing the source and destination directories, use
PUSHD
to switch the current directory to the source directory.Read each line of a
dir /b /ad
command into%%b
in turn (basic list without directorynames (/a-d
) - selecting both all.zip
and all.rar
files.The
echo
line is just to show the filename found. It can be deleted at your whim.Then examine the string in
%%b
, using delimiters of[]()
. Assign the first token to%%s
, the next to%%t
...remainder of the line to%%w
The
echo
line is just to show the way the filename is tokenised - each token is shown between '++'. It can be deleted at your whim.Using your example filename,
[2019]Text1(text2).zip
,%%s
should be2019
,%%t
Text1,%%u
text2
,%%v
.zip
and%%w
should be empty.If
%%w
is empty, then check that%%v
is either.zip
or.rar
, case-insensitive (/i
) and if%%v
matches one or the other, execute amd
to create the destination directory (if that directory already exists, an error message will be generated which is suppressed by2>nul
) and the file is then moved to that directory.Finally, the
popd
returns to the original current directoryNote that the
MD
andMOVE
are merelyecho
ed so that you can see whether the instructions are correct. To actually perform theMD
andECHO
you will need to remove theecho
keyword from those lines.The various checks are a reasonably crude attempt to make sure that only files matching
[2019]Text1(text2).zip
will be processed. A file named[2019]Text1(text2)extra.zip
or[2019](text2).zip
would fail the checks and not be processed, although[[2019]]Text1(text2).zip
would pass the checks.You could change the
dir
filemask to eg.[*]*(*).zip
but even that would pass some non-compliant filenames.The
move
command will generate a1 fie(s) moved
message when it washes its socks. You can suppress this message by appending>nul
to themove
command.