0

I'm trying to write a code that will remove it from a file and app address. To remove the address to the \ last. How can I do this?

old_path = C:\\Users\zivsi\AppData\Local\WhatsApp\WhatsApp.exe
*event* remove up to the last \
new_path = WhatsApp.exe

old_path = C:\\Users\zivsi\Desktop\alarm.exe
*same event* remove up to the last \
new_path = alarm.exe
  • see [Path documentation](https://docs.python.org/3/library/pathlib.html#concrete-paths), check `parent()` and `name()`methods. – Eric Frigade Mar 29 '20 at 08:06
  • Does this answer your question? [How to get only the last part of a path in Python?](https://stackoverflow.com/questions/3925096/how-to-get-only-the-last-part-of-a-path-in-python) – one Mar 29 '20 at 08:06
  • @Alpha It is not recommended to use `os.path` anymore. Library `Path` is supposed to be used (python3-x), I do not know for python 2 – Eric Frigade Mar 29 '20 at 08:10

0 Answers0