Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Ok. this is a solved problem. Use the framework provided filepath, or os.path matching package instead of this "inventing the wheel, but this time, as a triangle" shit.
-
donuts236725y@magicMirror string path = "c:\some\long\path\file.txt"
Java will say that string is bad no matter what. There is no shortcut to tell it not to escape the \ unlike Python or C#
If you put that in a Linux shell script, will also fail -
donuts236725y@muttley Linux and programming languages don't because \ is the escape character for like \t, \n. Needs to escape it with \\ or use /
-
@billgates in C# I use a combination of:
System.IO.Path.Combine
@“”
StringBuilder
String.Replace
Not all at once, but it depends on what I have in the function and how much I want to refactor. -
@billgates solution is easy.
1. why do you need to convert?
2. what code are you using to convert?
1 - the answer is usualy, no actual direct need. Can pass as arg on command line, or file with paths.
2. use the framework path standard methods to handle path loading, manipulation and usage. -
donuts236725y@bkwilliams yes @ and r"" are compiler supported helpers which just tells it treat everything in the following "" literally. They make things easier but not all languages have them and I don't think Linux shell script does either.
At run/compile time they are converted to \\.
So I copy a file path from Explorer, I need all the \ escaped or changed to an / -
donuts236725y@magicMirror I am running a simple program that just needs some input/output path. Yes I could prompt Every time it change the run configs but it's more efficient to just hard code it into the program so I don't have to input it every time.
-
donuts236725y@muttley because Windows Explorer converts and outputs all paths with \. Also I think cmd doesn't like / for some things...
-
@billgates Yup. I understand the logic.
Reminds me of when I just started to play around with perl circa 1999. coded a horrendus zero padding monster, using if statements only. Worked, but damn it was hard to look at later..... -
if you are able to code them, and they are usable by others, that's great.
Most of tools I do are done in such a hurry that I'm the only one to understand them....
I was just going over some projects I need to transfer to others team members and was reminded of all the utility apps I created. Particularly on that covers Windows paths to Linux....
Or basically path.Replace("\\","/") in a GUI.
I actually use it a lot whenever I hardcode a file path in Java for testing or make some partial path Linux compliant.
I think it saves me a lot of time but I'm the only person I think that creates these apps... basically for anything I find myself repeating often... Even these simple things.
Am I weird? Or just good at identifying things that can be outsourced? And outsourcing them?
rant
musings