PowerShell Implement batch rename file _powershell

Source: Internet
Author: User

If you have a large folder with pictures in it and you want to rename the picture in the folder according to a uniform rule, the script for this article will be simple to demonstrate:

$i = 0
 
get-childitem-path c:\pictures-Filter *.jpg |
Foreach-object {
$extension = $_. Extension
$newName = ' pic_{0:d6}{1} '-f $i, $extension
$i + +
Rename-item-path $_. Fullname-newname $newName
}

All of the JPG files in the folder have been renamed, and the new picture filename is shaped like "pic_" and a 6-digit number, and you can make a few modifications to this template to complete a richer custom rule.

Small note: When I was still using padleft and padright, I found that the original string formatting parameters were already supported.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.