0

How do i make python listen for changes to a folder on my desktop, and every time a file was added, the program would read the file name and categorize it it based on the extension?

This is a part of a more detailed program but I don't know how to get started on this part. This part of the program detects when the user drags a file into a folder on his/her desktop and then moves that file to a different location based on the file extension.

1
  • I don't think this is a duplicate based on the referenced existing answer. It doesn't address the core of OP's question. Commented Nov 15, 2018 at 0:08

1 Answer 1

0

Periodically read the files in the folder and compare to a set of files remaining after the last execution of your script. Use os.listdir() and isfile().

Read the extension of new files and copy them to a directory based on internal rules. This is a simple string slice, e.g., filename[-3:] for 3-character extensions.

Remove moved files from your set of last results. Use os.rename() or shutil.move(). Sleep until next execution is scheduled.

Sign up to request clarification or add additional context in comments.

1 Comment

An alternative to the string slice is to split on '.' and retain the last element. That would capture any length extension.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.