RSS

Delete part of a filenames in a folder with python

21 Dec
import os
#ask user for DIR 
files_dir=input("Enter DIR path:")
for i in files_dir:
    if i == "\\":
        index_of_the_slash = files_dir.find(i)
        filePath= files_dir.replace(rename_files_dir[index_of_the_slash],"/")
#change dir
os.chdir(filePath)
#list of files in dir
filenames=os.listdir()
#Replace x with the number of letters you need
for m in filenames:
    #customise to get what you need
    os.rename(m,(m[0:x]+".pdf"))

 
Leave a comment

Posted by on December 21, 2020 in Python

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: