文件夹中替换或删除所有文件的文件名某些字符 [英] Replace or delete certain characters from filenames of all files in a folder

查看:1084
本文介绍了文件夹中替换或删除所有文件的文件名某些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除特定的字符或通过一些批处理文件执行,替换与其他人物的某些字符在一个旅途中的Windows文件夹中的所有文件的文件名,有一个DOS命令是什么?

How do I delete certain characters or replace certain characters with other characters by some batch file execution, for filenames of all files in a Windows folder in one go, is there a DOS command for that?

推荐答案

使用PowerShell中做任何事情聪明的DOS提示符。在这里,我已经展示了如何批量重命名所有在当前目录下,通过与 _ 替换它们包含空格的文件和目录下划线。

Use PowerShell to do anything smarter for a DOS prompt. Here, I've shown how to batch rename all the files and directories in the current directory that contain spaces by replacing them with _ underscores.

Dir |
Rename-Item -NewName { $_.Name -replace " ","_" }

编辑:结果
(可选)的的位置对象命令可以用来为过滤器出不合格的连续的命令对象的(命令让)。下面是一些例子来说明它的灵活性能买得起你:

EDIT :
Optionally, the Where-Object command can be used to filter out ineligible objects for the successive cmdlet (command-let). The following are some examples to illustrate the flexibility it can afford you:


  • 要跳过任何文档文件

  • To skip any document files

Dir |
Where-Object { $_.Name -notmatch "\.(doc|xls|ppt)x?$" } |
Rename-Item -NewName { $_.Name -replace " ","_" }


  • 要仅处理目录(pre-3.0版本)

  • To process only directories (pre-3.0 version)

    Dir |
    Where-Object { $_.Mode -match "^d" } |
    Rename-Item -NewName { $_.Name -replace " ","_" }
    

    的PowerShell 3.0引入了新的目录标志。您还可以使用目录-Directory 那里。

    PowerShell v3.0 introduced new Dir flags. You can also use Dir -Directory there.

    要跳过已经包含一个下划线(或其它字符)的任何文件

    To skip any files already containing an underscore (or some other character)

    Dir |
    Where-Object { -not $_.Name.Contains("_") } |
    Rename-Item -NewName { $_.Name -replace " ","_" }
    


  • 这篇关于文件夹中替换或删除所有文件的文件名某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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