Michele Ceccacci
Michele Ceccacci

Reputation: 1

Permission denied in copying textfiles

I want to move a file to another folder, but my permissions seems to be denied.

I have tried googling the problem, and although this is probably a pretty simple problem, I am not able to find solutions. I am the administrator on the system.

import os
import shutil
import re
textregex = re.compile(r'(.*).txt')
folder_files = os.listdir('D:\\progetti python\\renamedates.py\\dates')
for filename in folder_files:
    txtfiles = textregex.findall(filename)
    print('found some text files: ' + filename)
    for file in txtfiles:
        shutil.copy(f'{file}','D:\\progettipython\\renamedates.py\\newfolder')

I expect to copy my file (which is a textfile) without having my copy denied.

Upvotes: 0

Views: 98

Answers (1)

Fabian
Fabian

Reputation: 1150

I can give you an example how to copy just .txt from folder a to folder b:

using glob to easy check for textfile ext.

import shutil
import glob

textfiles = glob.glob(r'C:\foldera\*.txt')
for filename in textfiles:
    shutil.copy(f'{filename}',r'C:\folderb')

Upvotes: 1

Related Questions