【问题标题】:How to batch rename a file of specific file type within subdir?如何批量重命名子目录中特定文件类型的文件?
【发布时间】:2014-04-27 02:31:18
【问题描述】:

我想批量重命名特定子目录中的所有文件。为什么下面会出现语法错误?

RENAME .\webapps\*.war .\webapps\Test.war

【问题讨论】:

  • 请您编辑您的问题以包含您收到的语法错误吗?
  • 这也会给所有文件同名?!这有意义吗?
  • 语法是whatToRename howToRename,所以应该没有路径。

标签: windows batch-file


【解决方案1】:

您的陈述中有一些混淆:您想将所有文件更改为相同的名称吗?这是不可能的。

你可能会错误地使用rename,请参考man rename

NAME
   rename - renames multiple files

SYNOPSIS
   rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

DESCRIPTION
   "rename" renames the filenames supplied according to the rule specified as the first argument.    The perlexpr argument is a Perl expression which is
   expected to modify the $_ string in Perl for at least some of the filenames specified.  If a given filename is not modified by the expression, it will not
   be renamed.  If no filenames are given on the command line, filenames will be read via standard input.

   For example, to rename all files matching "*.bak" to strip the extension, you might say

           rename 's/\.bak$//' *.bak

   To translate uppercase names to lower, you'd use

           rename 'y/A-Z/a-z/' *

OPTIONS
   -v, --verbose
           Verbose: print names of files successfully renamed.

   -n, --no-act
           No Action: show what files would have been renamed.

   -f, --force
           Force: overwrite existing files.

This post 也可能有用。

【讨论】:

    【解决方案2】:

    您不能使用包含路径的目标名称来rename

    RENAME .\webapps\*.war Test.war
    

    应该可以。

    【讨论】:

      猜你喜欢
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 2017-06-21
      • 1970-01-01
      • 2015-01-23
      • 2010-11-04
      相关资源
      最近更新 更多