#๐ someone explain this
18 messages ยท Page 1 of 1 (latest)
@trail musk
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.
you probably need to add the folder name in the file path to it while renaming
how would it know what the file is called
he said i cant find the file called this
how would he know its name if he cant find it
if the only way to get the name is through iterating
he obviously can find it if he can name it
os.rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)```
Rename the file or directory *src* to *dst*. If *dst* exists, the operation will fail with an [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError) subclass in a number of cases:
On Windows, if *dst* exists a [`FileExistsError`](https://docs.python.org/3/library/exceptions.html#FileExistsError) is always raised. The operation may fail if *src* and *dst* are on different filesystems. Use [`shutil.move()`](https://docs.python.org/3/library/shutil.html#shutil.move) to support moves to a different filesystem.
oooooooooo
So what os.listdir is able to find is not shared with os.rename
provide the full file path in os.rename
you genius
or better yet, start using pathlib instead (here is a good comparison and conversion table): https://docs.python.org/3/library/pathlib.html#corresponding-tools
from pathlib import Path
for file_path in Path("spriteicons").iterdir():
new_file_path = file_path.with_name("civ_" + file_path.name[4:].lower())
file_path.rename(new_file_path)
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.