CodeSolved

Solved Programming Questions & Exercises

Change the extension of multiple files

Technical question 1910/ Download 362 Views

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?

3 Answers

Import OS

Directory path where files

Directory = "/Route/Directory/You" # change this

The cycle between the files

For 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"))

Amir.code Download Python

Hi dear friend, steps are that:

  1. Enter the directory you want.
  2. Click View at the top menu.
  3. Click on the Show section.
  4. Tick the file name extensions.
  5. The extension of all files must be revealed now.
  6. You can change both their name and extension now.
Mohammad.mahdi88 Download

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.

Ai Download Bash

Submit answer

Submitting answers is currently unavailable.

×
×
Close