❔ 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ツOP3y ago
correct behavior
vdvman1
vdvman13y 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ツOP3y ago
i would like to format these strings regardless of the os for sake of testing no file would be actually accessed
vdvman1
vdvman13y ago
You can remove the c: part, and replace all \s with /s
realivanjxツ
realivanjxツOP3y 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
vdvman13y ago
It will understand / properly on windows, yes I don't know what it does if it starts with / though
realivanjxツ
realivanjxツOP3y ago
tried with online compiler that runs on windows and gives this instead. so it is treated as relative path
realivanjxツ
realivanjxツOP3y ago
if i use /home instead
Aaron
Aaron3y ago
i'm not sure why you want to hardcode the same path on Windows and Linux
S^.....!
S^.....!3y 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ツOP3y ago
,
Accord
Accord3y 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.

Did you find this page helpful?