开发者

Renaming a file and remove 'dot' and replace it with' _'

I have set of files in a folder with name like abcd.15678 I want to remove the . and replace it with _

Pls suggest the windows 开发者_Python百科command to do this


This solution is reposted from How to Batch Rename Files in Windows: 4 Ways to Rename Multiple Files by Chris Hoffman

PowerShell offers much more flexibility for renaming files in a command-line environment. Using PowerShell, you can pipe the output of one command – known as a “commandlet” in PowerShell terms — to another command, just like you can on Linux and other UNIX-like systems.

Renaming a file and remove 'dot' and replace it with' _'

First of all, open Powershell ISE and then navigate to the directory (folder) that has the files and folders you'd like to rename by using this command:

cd "C:\your\directory\"

Renaming a file and remove 'dot' and replace it with' _'

The two important commands you’ll need are Dir, which lists the files in the current directory, and Rename-Item, which renames an item (a file, in this case). Pipe the output of Dir to Rename-Item and you’re in business.

After you launch PowerShell ISE, use the cd command to enter the directory containing your files. You should put the files in their own directory so you don’t accidentally rename other files.

For example, let’s say we don’t want the dot character in our file names – we’d rather have an underscore instead.

The following command lists the files in the current directory and pipes the list to Rename-Item. Rename-Item replaces each dot character with an underscore.

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

Consult Microsoft’s documentation on the Rename-Item commandlet if you want help performing other, more advanced operations.


There isn't a windows command to do this. You should consider writing a script of some sort that obtains a directory listing and enumerates through each entry: changes the dot to an underscore, and calls the windows rename command appropriately.


Actually this should work :

Dir | Rename-Item –NewName { $_.Name.Replace(".","_") }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜