【问题标题】:.bat file to rename and move files with prompt.bat 文件以提示重命名和移动文件
【发布时间】:2012-10-25 13:29:01
【问题描述】:

我对此完全陌生,但我正在尝试创建一个 .bat 文件,该文件允许我重命名指定文件夹中的一对文件并将它们移动到子文件夹中。我遇到的问题是我想要一个提示来识别/选择要重命名和移动的文件。

示例文件名是:

A1234, A1235, A1236, B1234, B1235, B1236, etc.

有没有办法让用户输入文件的共享名称(例如 1234)并重命名并将两个文件移动到指定的子文件夹?

我们将不胜感激!

【问题讨论】:

  • 我认为您可以使用搜索命令以模式“?1234”进行搜索,然后在循环中对找到的结果进行迭代进行重命名。请注意,字符串中的? 是通配符。
  • @MukulGoel 你能给我更多的澄清吗?这远远超出了我知道该怎么做。我承认,我认为这会比结果要简单得多......

标签: batch-file


【解决方案1】:

建议的方法

部分问题

part I am having trouble with is that I am wanting a prompt to come up to identify/select the files to be renamed and moved. Is there a way to bring up a prompt that allows the user to type the shared name (ex 1234)of the files and rename and move both files to the designated subfolder?

使用wildcard 进行搜索操作,例如"?1234" 用于上面突出显示的情况(应该对所有可接受和预期的模式进行概括,"*1234*" 是最通用的)

现在在 For 循环中对搜索获得的结果执行 RENAME

正如您建议您是 Batch 的新手,以下教程将帮助您构建文件。寻找像VariablesFor Loop这样的元素

Batch Tutorial

【讨论】:

    【解决方案2】:

    给你

    @echo off
    set /p file=Please type shared name: 
    for %%a in (C:\Folder\?%file%.*) do (
    move "%%a" subdir
    ren "subdir\%%a" newname.*
    )
    

    【讨论】:

      猜你喜欢
      • 2014-06-07
      • 2016-02-17
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      相关资源
      最近更新 更多