Change backslash to forward slash in windows batch file
This will change the back-slashes to forward-slashes in a variable: set “variable=E:\myfiles\app1\data\*.csv” set “variable=%variable:\=/%” echo “%variable%”
This will change the back-slashes to forward-slashes in a variable: set “variable=E:\myfiles\app1\data\*.csv” set “variable=%variable:\=/%” echo “%variable%”
There’s no need to use replace for this. What you have is a encoded string (using the string_escape encoding) and you want to decode it: >>> s = r”Escaped\nNewline” >>> print s Escaped\nNewline >>> s.decode(‘string_escape’) ‘Escaped\nNewline’ >>> print s.decode(‘string_escape’) Escaped Newline >>> “a\\nb”.decode(‘string_escape’) ‘a\nb’ In Python 3: >>> import codecs >>> codecs.decode(‘\\n\\x21’, ‘unicode_escape’) ‘\n!’
There are two options: using pattern matching (slightly slower): s = s.replaceAll(“/$”, “”); or: s = s.replaceAll(“/\\z”, “”); And using an if statement (slightly faster): if (s.endsWith(“https://stackoverflow.com/”)) { s = s.substring(0, s.length() – 1); } or (a bit ugly): s = s.substring(0, s.length() – (s.endsWith(“https://stackoverflow.com/”) ? 1 : 0)); Please note you need to use … Read more
No need to use an echo + a pipe + sed. A simple substitution variable is enough and faster: echo ${DATE//\//\\/} #> 04\/Jun\/2014:15:54:26
The answer is that you can’t, unless your filesystem has a bug. Here’s why: There is a system call for renaming your file defined in fs/namei.c called renameat: SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname) When the system call gets invoked, it does a path lookup (do_path_lookup) … Read more
At least three ways: A regular expression: var result = /[^/]*$/.exec(“foo/bar/test.html”)[0]; …which says “grab the series of characters not containing a slash” ([^/]*) at the end of the string ($). Then it grabs the matched characters from the returned match object by indexing into it ([0]); in a match object, the first entry is the … Read more
/ is the path separator on Unix and Unix-like systems. Modern Windows can generally use both \ and / interchangeably for filepaths, but Microsoft has advocated for the use of \ as the path separator for decades. This is done for historical reasons that date as far back as the 1970s, predating Windows by over … Read more