Python Forum
Can anyone help me successfully run this code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can anyone help me successfully run this code?
#11
(Aug-17-2023, 03:20 PM)deanhystad Wrote: Do you really mean "C:\Users\User\Desktop" or do you mean the desktop for the current user? If the latter, you can ask windows for the current user's %HOMEPATH%. This program lists all the files on your desktop.
import os
from pathlib import Path

desktop = Path(os.environ["USERPROFILE"]) / "Desktop"
print(*desktop.iterdir(), sep="\n")
To get paths for Desktop\tabs.json and Desktop\tabs_oldercopywithalternatelinks.json:
work_files = desktop / "the-great-suspender-restore-urls-0.4"
tabs_path = work_files / "tabs.json"
tabs_copy_path = work_files / "bs_oldercopywithalternatelinks.json" 
if the path is really hard coded (will always be C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4), use a string. I suggest changing the "\" to "/" so Python doesn't interpret "\the" as "<tab>he".
from pathlib import Path

work_files = Path("C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4")
tabs_path = work_files / "tabs.json"
tabs_copy_path = work_files / "bs_oldercopywithalternatelinks.json"

I chose the third code excerpt, as it's exactly what I need! ^_^ Just one more question: Where exactly do I put the third code excerpt into the main code?
Reply


Messages In This Thread
RE: Can anyone help me successfully run this code? - by TheMouseAvenger - Sep-08-2023, 02:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how do I successfully use PDO with my ODBC for MSSQL? cyberion1985 3 6,659 Jun-26-2018, 04:44 PM
Last Post: Maverick494
  Cannot successfully install NumPy aniketmone2017 3 7,415 Dec-29-2016, 02:14 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020