0
import os

def soldier(ppth):
            pth= os.listdir(ppth)
            for filename in pth:
                os.rename(filename,filename.lower())
            print(pth)
soldier("D://QwertyA")
bad_coder
  • 11,289
  • 20
  • 44
  • 72
BABA ADAM
  • 21
  • 3
  • Even if i use os.rename(filename,filename.capitalize()). Its generating an error FileNotFoundError: [WinError 2] The system cannot find the file specified: 'asd.docx' -> 'Asd.docx' – BABA ADAM May 14 '21 at 21:13
  • You probably need to use the full path to the file `f"{ppth}/{filename}"` – cam May 14 '21 at 21:22

2 Answers2

1

You can use the capitalize method.

string.capitalize()

def soldier(ppth):             
    pth= os.listdir(ppth)             
    for filename in pth:                 
        os.rename(f"{ppth}/{filename}",f"{ppth}/{filename.lower().capitalize()}")
cam
  • 778
  • 6
  • 9
0

You can try something like this.

import os
fileName = 'test.txt'
newFileName = fileName.capitalize()
print(newFileName)
os.rename(f'/path/to/file/{fileName}',f'/path/to/file{newFileName}')

Seems like my file has been capitalized.

enter image description here

Buddy Bob
  • 5,829
  • 1
  • 13
  • 44