命令行(或批处理文件)重命名文件夹中的所有文件(Windows) [英] Command Line (or batch file) rename all files in a folder (Windows)

查看:1423
本文介绍了命令行(或批处理文件)重命名文件夹中的所有文件(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的所有文件与文件名格式如下重命名的文件夹中;

I need to rename all of the files in a folder with the following filename format;

ITEMID-直bottle.png

itemID-straight-bottle.png

ITEMID-bottle.png

itemID-bottle.png

我怎样才能做到这一点了CMD脚本,或在命令行?

How can i accomplish this with a cmd script or in the command line?

例如;

REDHI20806-直bottle.png TO REDHI20806-bottle.png

REDHI20806-straight-bottle.png TO REDHI20806-bottle.png

我应该说,这是在Windows和我想使用命令行或批处理文件到特定的驱动器上运行的所有文件重命名该文件夹中的

I should have said, this is in Windows and i want to use either command line or a batch file to run this renaming on all files in a folder on a specific drive

推荐答案



窗口上,您可以使用PowerShell,即默认情况下安装在Windows 7上,并可以下载并安装在previous版本。使用PowerShell,你可以做重命名为:

short answer


On Windows, you can use PowerShell, that is installed by default on Windows 7, and can be downloaded and installed on previous versions. With PowerShell you can do the rename as:

ls | foreach-object -process {ren $_ (%{$_ -replace "-straight",""})}

Unix / Linux操作系统后,要安装什么特殊需求,你可以因为这样做重命名:

On Unix/Linux, nothing specific needs to be installed, and you can do the rename as:

ls | awk '{print("mv "$1" "$1)}' | cut -f -3,5- -d '-' | sh

结果

PS C:\rename-me> ls

    Directory: C:\rename-me

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         10/9/2011   1:35 PM          0 REDHI20806-straight-bottle.png
-a---         10/9/2011   1:35 PM          0 REDHI20807-straight-bottle.png
-a---         10/9/2011   1:35 PM          0 REDHI20808-straight-bottle.png
-a---         10/9/2011   1:35 PM          0 REDHI20809-straight-bottle.png
-a---         10/9/2011   1:35 PM          0 REDHI20810-straight-bottle.png

PS C:\rename-me> ls | foreach-object -process {ren $_ (%{$_ -replace "-straight",""})}

结果

PS C:\rename-me> ls

    Directory: C:\rename-me

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         10/9/2011   1:35 PM          0 REDHI20806-bottle.png
-a---         10/9/2011   1:35 PM          0 REDHI20807-bottle.png
-a---         10/9/2011   1:35 PM          0 REDHI20808-bottle.png
-a---         10/9/2011   1:35 PM          0 REDHI20809-bottle.png
-a---         10/9/2011   1:35 PM          0 REDHI20810-bottle.png

结果

$ ls -l
total 0
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20806-straight-bottle.png
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20807-straight-bottle.png
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20808-straight-bottle.png
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20809-straight-bottle.png
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20810-straight-bottle.png

$ ls | awk '{print("mv "$1" "$1)}' | cut -f -3,5- -d '-' | sh

结果

$ ls -l
total 0
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20806-bottle.png
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20807-bottle.png
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20808-bottle.png
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20809-bottle.png
-rw-r--r--  1 user  staff  0 Oct  7 00:54 REDHI20810-bottle.png

这篇关于命令行(或批处理文件)重命名文件夹中的所有文件(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆