Python Bulk Modify file name

Source: Internet
Author: User

Recently downloaded a batch of video from the Baidu cloud disk, however, these video filenames have ads. I felt uncomfortable when I was a neat freak, so I tried to change it. But a change of file name is too troublesome, Lenovo to the amateur saw Python, so with Python wrote a few lines of code easily batch modified file name.

The code is as follows:

1 #Coding:utf-82 ImportOs,sys
#获取目录下所有的文件名 #
3Videos_name=os.listdir ('D:\\videos')
#循环遍历文件名 #
4 forTempinchVideos_name:5 PrintTemp6new_name=temp[0:6]+'. flv'7 Printnew_name8Os.rename ('d:\\videos\\'+temp,'d:\\videos\\'+new_name)

Python learning is really interesting, I heard Python next year in a province to be included in the college entrance examination, haha.

Python Bulk Modify file name

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.