❔ Path.GetFullPath behavior on linux

how to get full path correctly? if i use /home/x/deep as abs it works fine and gives /home/x/test.txt. im on linux.
12 Replies
realivanjxツ
realivanjxツOP2y ago
correct behavior
vdvman1
vdvman12y ago
Backslashes aren't part of the directory structure on linux, and C: isn't a linux thing at all So the path you specified in your first screenshot is processed as a folder called c:\home\x\deep\.. and a file called text.txt
realivanjxツ
realivanjxツOP2y ago
i would like to format these strings regardless of the os for sake of testing no file would be actually accessed
vdvman1
vdvman12y ago
You can remove the c: part, and replace all \s with /s
realivanjxツ
realivanjxツOP2y ago
ok i will try it. thanks what if i run this inside windows? will it respect the / and give the same result? i dont have windows machine atm since / is also a valid separator on windows afaik
vdvman1
vdvman12y ago
It will understand / properly on windows, yes I don't know what it does if it starts with / though
realivanjxツ
realivanjxツOP2y ago
tried with online compiler that runs on windows and gives this instead. so it is treated as relative path
realivanjxツ
realivanjxツOP2y ago
if i use /home instead
Aaron
Aaron2y ago
i'm not sure why you want to hardcode the same path on Windows and Linux
S^.....!
S^.....!2y ago
And also, I don't think C:\home would be preferred home path in windows. Try to access the environment variable userprofile
realivanjxツ
realivanjxツOP2y ago
,
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server