gpt4 book ai didi

windows - 使用正则表达式批量移动文件到新文件夹

转载 作者:行者123 更新时间:2023-12-02 01:37:17 29 4
gpt4 key购买 nike

我不是开发人员,我只是在寻找获取代码。

我的文件夹:

default-0.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f793929196829b83dac7b7c58fd9879990" rel="noreferrer noopener nofollow">[email protected]</a>
default-1.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4420212225312830697504763c6a342a23" rel="noreferrer noopener nofollow">[email protected]</a>
default-2.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2743424146524b530a1567155f09574940" rel="noreferrer noopener nofollow">[email protected]</a>
default-3.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1672737077637a623b2556246e38667871" rel="noreferrer noopener nofollow">[email protected]</a>
default-4.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1b5b4b7b0a4bda5fce591e3a9ffa1bfb6" rel="noreferrer noopener nofollow">[email protected]</a>
default-5.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d0d1d2d5c1d8c09981f486cc9ac4dad3" rel="noreferrer noopener nofollow">[email protected]</a>
default-6.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86e2e3e0e7f3eaf2abb0c6b4fea8f6e8e1" rel="noreferrer noopener nofollow">[email protected]</a>
default-7.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f4b4a494e5a435b02186f1d57015f4148" rel="noreferrer noopener nofollow">[email protected]</a>
default-8.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f89c9d9e998d948cd5c0b8ca80d688969f" rel="noreferrer noopener nofollow">[email protected]</a>
default-9.png
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f094959691859c84ddc9b0c288de809e97" rel="noreferrer noopener nofollow">[email protected]</a>
...

我只想将文件名为“@2...”的文件和任何文件扩展名移动到“新文件夹”。

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2440414245514850091464165c0a544a43" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b5f5e5d5a4e574f160a7b0943154b555c" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5236373433273e267f6012602a7c223c35" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b7f7e7d7a6e776f36285b2963356b757c" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e084858681958c94cdd4a0d298ce908e87" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c18191a1d09100851493c4e04520c121b" rel="noreferrer noopener nofollow">[email protected]</a>
default-<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="162056246e38667871" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2440414245514850091364165c0a544a43" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5236373433273e267f6a12602a7c223c35" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c68696a6d79607821354c3e74227c626b" rel="noreferrer noopener nofollow">[email protected]</a>
...

我尝试使用正则表达式:(^.+@2.+.$) 请参阅检查 regex101获取完整匹配文本。

我尝试了我的代码但不起作用:

@echo off
setlocal enabledelayedexpansion
for /f %%f in ('dir /b | findstr /r "(^.+@2.+.$)") do (
md "new folder"
move "%%~f" "moved folder"
)
Echo done
pause

谁能帮帮我,我错了什么?

更新:感谢@develc(已回答)和@Mofi(已编辑)这很有效,我的文件的完美数量与正则表达式匹配。

md "new folder"
move "*@2x*" "new folder"

另一种方法:这有效,但 0.1% 无法移动,因为无法检测到文件名有注释,例如 example@2x - if comment.png。感谢@Hackoo的回答

@echo off
MD "new folder">nul 2>&1
setlocal enabledelayedexpansion
for /f %%f in ('dir /b *@2*') do (
move "%%~f" "new folder"
)
Echo done
pause

最佳答案

可以使用这样的东西:

md "new folder"
move "*@2x*" "new folder"

在批处理文件中,*a 表示 a 结尾的所有内容; b* 表示 b 开头的所有内容; a*b 表示 a 开头并以 b 结尾的所有内容; a?b 表示 a 开头的所有内容,之间有一个字符 a b 并以 b结尾。因此,*所有内容的通配符,?每个字符的通配符。

参见:MS-DOS and Windows Wildcard Characters在 Microsoft 的文档网站上。

关于windows - 使用正则表达式批量移动文件到新文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72153056/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com