1
i am developing a python script, which he needs to access a folder and within that folder has 3 folders which has several files
example:
Pastaprincipal
|
| ---- pasta1
| ---- arquivo.pdf
|
| ---- pasta2
| ---- arquivo.pdf
|
| ---- pasta3
| ---- arquivo.pdf
what I need to do and rename these acquisitions of extension PDF
and then remove them from the folders by moving to the PastaPrincipal
.
being like this
Pastaprincipal
|
| ---- pasta1
|
| ---- pasta2
|
| ---- pasta3
| ---- renomeado.pdf
| ---- renomeado.pdf
| ---- renomeado.pdf
here is my code
import os
from time import sleep
def Files(filepath):
print('Lendo a pasta principal [{pasta}]...'.format(pasta=os.path.basename(filepath)))
sleep(1)
for files in os.listdir(path=filepath):
print(files)
os.chdir(files)
if __name__ == '__main__':
filess = input('deretório principal:')
Files(filess)
when I use the os.chdir()
so I can enter inside the folders it returns me an error FileNotFoundError: [WinError 2] The system cannot find the file specified: 'pasta1'
.
what I want to do is rename before I can move the files.
Can someone please help me :)
Thanks for the help, it worked obriagdo
– user172242
if it worked, consider marking this answer as accepted - you can still vote for other answers you think are cool.
– jsbueno