将文件移动到具有部分名称的文件夹

发布于 2024-09-07 22:37:15 字数 160 浏览 5 评论 0原文

我有大约 250 个文件需要移动到特定文件夹。问题是该文件夹只有文件的部分名称。

例如,我需要将文件“12345.txt”移动到文件夹“12345 - hello”,因为每个文件夹均以实际文件名开头。

我可以在 DOS 中的批处理文件中执行此操作吗?

谢谢。

I have about 250 files that I need to move to a specific folder. The problem is that folder only have the partial name of the files.

For example, I need to move file "12345.txt" to folder "12345 - hello" as each folder starts by the actual file name.

Can I do this in a batch file in DOS?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红尘作伴 2024-09-14 22:37:15

假设Windows,这实际上并不难:

@echo off
rem loop over all files
for %%f in (*) do call :process "%%f"

rem this is necessary to avoid running the subroutine below
rem after the loop above ended
goto :eof

rem subroutine that gets called for every file
rem this finds the first matching folder and moves the file there
:process
rem the /d loops over all directories - the mask ensures that
rem the directory name starts with the given file name (without
rem extension)
for /d %%d in ("%~n1*") do (
    echo Moving "%~1" to "%%d" ...
    move "%~1" "%%d"
    rem Return since the file was moved already
    goto :EOF
)

也可以在我的SVN存储库中找到。

Assuming Windows, it's actually not hard:

@echo off
rem loop over all files
for %%f in (*) do call :process "%%f"

rem this is necessary to avoid running the subroutine below
rem after the loop above ended
goto :eof

rem subroutine that gets called for every file
rem this finds the first matching folder and moves the file there
:process
rem the /d loops over all directories - the mask ensures that
rem the directory name starts with the given file name (without
rem extension)
for /d %%d in ("%~n1*") do (
    echo Moving "%~1" to "%%d" ...
    move "%~1" "%%d"
    rem Return since the file was moved already
    goto :EOF
)

Can also be found in my SVN repository.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文