How can I obtain the case-sensitive path on Windows?

You can use this function: [DllImport(“kernel32.dll”, SetLastError=true, CharSet=CharSet.Auto)] static extern uint GetLongPathName(string ShortPath, StringBuilder sb, int buffer); [DllImport(“kernel32.dll”)] static extern uint GetShortPathName(string longpath, StringBuilder sb, int buffer); protected static string GetWindowsPhysicalPath(string path) { StringBuilder builder = new StringBuilder(255); // names with long extension can cause the short name to be actually larger than // the … Read more

python replace backslashes to slashes

You can use the string .replace() method along with rawstring. Python 2: >>> print r’pictures\12761_1.jpg’.replace(“\\”, “https://stackoverflow.com/”) pictures/12761_1.jpg Python 3: >>> print(r’pictures\12761_1.jpg’.replace(“\\”, “https://stackoverflow.com/”)) pictures/12761_1.jpg There are two things to notice here: Firstly to read the text as a drawstring by putting r before the string. If you don’t give that, there will be a Unicode error … Read more

How can I open files relative to my GOPATH?

Hmm… the path/filepath package has Abs() which does what I need (so far) though it’s a bit inconvenient: absPath, _ := filepath.Abs(“../mypackage/data/file.txt”) Then I use absPath to load the file and it works fine. Note that, in my case, the data files are in a package separate from the main package from which I’m running … Read more

How to get the file path in html in PHP?

You shouldn’t just use the $_GET you’ve got now. Your file is based in $_FILES[“csv_file”][“tmp_name”]. Best you review this tutorial, that basically says you need to do something like this: <?php if ($_FILES[“csv_file”][“error”] > 0) { echo “Error: ” . $_FILES[“csv_file”][“error”] . “<br />”; } else { echo “Upload: ” . $_FILES[“csv_file”][“name”] . “<br />”; … Read more

VBScript to open a dialog to select a filepath

There is another solution I found interesting from MS TechNet less customization but gets what you wanted to achieve. This returns the full path of the selected file. Set wShell=CreateObject(“WScript.Shell”) Set oExec=wShell.Exec(“mshta.exe “”about:<input type=file id=FILE><script>FILE.click();new ActiveXObject(‘Scripting.FileSystemObject’).GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>”””) sFileSelected = oExec.StdOut.ReadLine wscript.echo sFileSelected

Extract a part of the filepath (a directory) in Python

import os ## first file in current dir (with full path) file = os.path.join(os.getcwd(), os.listdir(os.getcwd())[0]) file os.path.dirname(file) ## directory of file os.path.dirname(os.path.dirname(file)) ## directory of directory of file … And you can continue doing this as many times as necessary… Edit: from os.path, you can use either os.path.split or os.path.basename: dir = os.path.dirname(os.path.dirname(file)) ## dir … Read more