Creating hotfolder INPUT OUTPUT Python. PermissionError: [Errno 13] Permission denied

16 views Asked by At

`Hey,

I want to create "IN" folder where I can move data base for data processing and ready file should move to "OUT" folder. But I stuck with PermissionError: [Errno 13] Permission denied. T have tried a lot of things, used shutil library, "run as administrator", all folders have permission, my file has access, but error is still here. Hope to get your help`

import os
import time
import pandas as pd
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler


main_folder = 'C:\\TEST_DATA'
input_folder = os.path.join(main_folder, 'C:\\TEST_DATA\\IN')
output_folder = os.path.join(main_folder, 'C:\\TEST_DATA\\OUT')
archive_folder = os.path.join(main_folder, 'C:\\TEST_DATA\\Archive')



def load_data(input_file_path):
    # Check if the file is CSV or Excel
    if input_file_path.endswith('.csv'):
        df = pd.read_csv(input_file_path, sep = ';', header= None, encoding='cp1252')
        df.columns = df.iloc[0]

Exception has occurred: PermissionError [Errno 13] Permission denied: 'C:\\TEST_DATA\\IN\\982567 - Vrije Academie - 14 september.csv' File "C:\Users\vhurin\Desktop\TEST FOLDER\myprogram.py", line 20, in load_data df = pd.read_csv(input_file_path, sep = ';', header= None, encoding='cp1252') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\vhurin\Desktop\TEST FOLDER\myprogram.py", line 146, in process_file df = load_data(input_file_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\vhurin\Desktop\TEST FOLDER\myprogram.py", line 143, in on_modified process_file(event.src_path) PermissionError: [Errno 13] Permission denied: 'C:\\TEST_DATA\\IN\\982567 - Vrije Academie - 14 september.csv'

class FileHandler(FileSystemEventHandler):
    def on_modified(self, event):
        if not event.is_directory and event.src_path.endswith(('.csv', '.xlsx', '.xls')):
            print(f"Detected new file: {event.src_path}")
            process_file(event.src_path)

def process_file(input_file_path):
    df = load_data(input_file_path)
    process_data(input_file_path, output_folder)

    # Move the input file to the archive folder
    archive_file_path = os.path.join(archive_folder, os.path.basename(input_file_path))
    shutil.move(input_file_path, archive_file_path)

if __name__ == "__main__":
    print("Monitoring the 'IN' folder for new files...")

    event_handler = FileHandler()
    observer = Observer()
    observer.schedule(event_handler, path=input_folder, recursive=False)
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()

    observer.join()
0

There are 0 answers