Change the extension of multiple files
Inside a directory there are a few files that have no extensions, but we know that the files are all of PDF, but they are so high that they can't be edited manually how can their extension be converted to PDF?
 
Inside a directory there are a few files that have no extensions, but we know that the files are all of PDF, but they are so high that they can't be edited manually how can their extension be converted to PDF?
 
                        
                        Import OS
Directory path where filesDirectory = "/Route/Directory/You" # change this
The cycle between the filesFor Fileneame in os.listdir (Directory):
FULL_PATH = os.path.join (Directory, Fileename)
# Only if the file is and the extension is not
if os.path.isfile(full_path) and '.' not in filename:
    new_name = filename + '.pdf'
    new_path = os.path.join(directory, new_name)
    os.rename(full_path, new_path)
    print(f"تغییر نام: {filename} → {new_name}")
Print ("All extensions without extension to pdf change"))
Hi dear friend, steps are that:
You can use the following code in the terminal to change the extension of the files to the PDF in a directory:
for f in *; do mv "$f" "$f.pdf"; done
This code changes all files without extension to the .PDF extension.
Submitting answers is currently unavailable.
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
                    normal—don’t worry 😊 
 Try checking out easier exercises and reviewing different answers
                    submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
                    might be correct even if it’s different from others.