import os
import shutil
from pathlib import Path
FC = {
"Images": [".jpg", ".png", ".gif", ".jpeg", ".bmp", ".tiff", ".raw",".avif"],
"Documents": [".pdf", ".docx", ".txt", ".doc", ".ppt", ".pptx", ".xls", ".xlsx"],
"Videos": [".mp4", ".mpeg", ".mkv", ".srt",".avi"],
"Music": [".mp3", ".wav", ".ogg"],
"Archives": [".zip", ".rar", ".tar.gz"],
"Code": [".py", ".js", ".html", ".css", ".ipynb", ".cpp", ".c"],
"Executables": [".exe", ".msi", ".sh"]
}
SourceFold = Path.home() / "Downloads"
def organize_files(source_path):
if not source_path.exists():
print("lol, not found. {source_path}")
for file in source_path.iterdir():
if file.is_dir:
continue
fs = file.suffix.lower()
moved = false
for cat, ext in FC.items():
if fs in ext:
dstf = source.path / cat
dstf.mkdir(exist_ok=true)
shutil.move(str(file), str(dstf / file.name))
print(f"Moved {file.name} โ {cat}/")
moved = True
break
if not moved:
others_folder = source_path / "Others"
others_folder.mkdir(exist_ok=True)
shutil.move(str(file), str(others_folder / file.name))
print(f"Moved {file.name} โ Others/")
print("Your files are moved sir - Construction people in your computer")
if __name__ == "__main__":
organize_files(sourcefold)```
so, it doesnt seem to get actually working, when i fix an indent: it doesnt output. if i dont, then theres errors.
#๐ alot of indent errors :(
20 messages ยท Page 1 of 1 (latest)
@inland quail
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.
Closes after a period of inactivity, or when you send !close.
!code
edit your message according to what the embed above tells you to
k
also, make sure you use 4 spaces for each indentation level, it will make it easier to spot mistakes
almost, it's better if you also include py just after the three backticks on the opening line, it will color highlight the code
nice!
now you only need a bit more spaces for each indentation level and your code will be looking much better, and who knows, maybe you'll find the problem with the indentation while increasing the indentation
okay, brb
oh wait it actually works?
last time i used the code it had errors
yeah i think all i needed to do was the indentation
not sure but yeah
looks like it should work from a quick look at it, but as i said, it will be easier to find/spot indentation problems if you use more spaces for each indentation level, PEP-8 says 4 spaces for each indentation level is the norm for python
This help channel has been closed. 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.