#๐Ÿ”’ function wont activate when it should

26 messages ยท Page 1 of 1 (latest)

pearl summitBOT
#

@iron kayak

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

iron kayak
#

not entirely sure why it isnt working

#

would be happy if anyone helped

left ferry
#

Idk ur proplem

#

Please be more detailed

#

I would recommend sending the in a paste

#

!paste

pearl summitBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

left ferry
#

Create ur own link and paste ur code in it and then send the link

#

It would be easier to read for me

iron kayak
left ferry
#

Sure

iron kayak
#

from os import scandir, rename
from os.path import splitext, exists, join
from shutil import move
from time import sleep
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import logging

source_dir = "C:\\Users\\K\\Downloads\\"
dest_dir_video = "C:\\Users\\K\\Documents\\Toolbar"

video_extensions = [".exe"]

def make_unique(dest, name):
    filename, extension = splitext(name)
    string1 = "Added"
    print(filename)
    name = f"{filename}({str(string1)}){extension}"
    print(filename+'2')
    return name


def move_file(dest, entry, name):
    print(f"{dest}/{name}")
    if exists(f"{dest}/{name}"):
        print("passed check")
        unique_name = make_unique(dest, name)
        oldName = join(dest, name)
        newName = join(dest, unique_name)
        rename(oldName, newName)
    move(entry, dest)

class MoverHandler(FileSystemEventHandler):
    def on_modified(self, event):
        with scandir(source_dir) as entries:
            for entry in entries:
                name = entry.name
                self.check_video_files(entry, name)

    def check_video_files(self, entry, name):
        for video_extension in video_extensions:
            if name.endswith(video_extension) or name.endswith(video_extension.upper()):
                move_file(dest_dir_video, entry, name)
                logging.info(f"Moved video file: {name}")

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    path = source_dir
    event_handler = MoverHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            sleep(10)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()
#

all this does currently is detect the file and place it in the destination folder.. i also want to name the file before or after it moves the file

iron kayak
valid prawn
#

This looks,,, overly complicated for doing something quite simple...

#

You just want to monitor a folder, and move and rename files that drop into it?

iron kayak
#

yeh

#

it works but it just wont rename it

iron kayak
left ferry
iron kayak
#

i understand how it works though

left ferry
#

Good

pearl summitBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ function wont activate when it should