批处理脚本为文件名添加前缀

发布于 2024-12-22 20:23:24 字数 143 浏览 3 评论 0原文

我试图在批处理脚本中重命名文件,如下所示:

rename %FOLDER%\* 1-*

但是当我运行脚本时,它会用前缀“1-”覆盖原始名称的前两个字符,而不是将其添加到文件名的开头。我该如何解决这个问题?

I am trying to rename files in a batch script like this:

rename %FOLDER%\* 1-*

but when I run the script It overwrites the first two characters of the original names with the prefix "1-" instead of adding it to the beginning of the file names. How can I work around this?

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

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

发布评论

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

评论(2

孤檠 2024-12-29 20:23:24

重命名只会重命名文件,您需要在前缀之后将文件名作为变量调用。下面是最终的工作结果。

cd %folder%
for %%a in (*) do rename "%%a" "1-%%a"

Rename will just rename the file, you would need to call the file name as a variable after the prefix. The below is what ended up working.

cd %folder%
for %%a in (*) do rename "%%a" "1-%%a"
最冷一天 2024-12-29 20:23:24

尝试以此为起点

@echo off 
for %%a in (%folder%\*) do (
  echo ren "%%~fa" "1-%%~nxa"
)

try this as a starting point

@echo off 
for %%a in (%folder%\*) do (
  echo ren "%%~fa" "1-%%~nxa"
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文