filepath

Splitting path strings into drive, path and file name parts

◇◆丶佛笑我妖孽 提交于 2019-11-28 02:55:18
问题 I am new to python and coding in general. I am trying to read from a text file which has path names on each line. I would like to read the text file line by line and split the line strings into drive, path and file name. Here is my code thus far: import os,sys, arcpy ## Open the file with read only permit f = open('C:/Users/visc/scratch/scratch_child/test.txt') for line in f: (drive,path,file) = os.path.split(line) print line.strip() #arcpy.AddMessage (line.strip()) print('Drive is %s Path is

Determining location of JVM executable during runtime

江枫思渺然 提交于 2019-11-28 02:34:57
问题 How does one obtain the location of the executable of the currently running JVM during runtime? I would like to instantiate another JVM as a subprocess using the ProcessBuilder class. I am aware that there is the java.home System property, but this doesn't specify the location of the JVM executable. I understand I could do something like this to get the path: System.getProperties().getProperty("java.home") + File.pathSeparator + "bin" + File.pathSeparator + "java" This code isn't platform

Strange path separators on Windows

自作多情 提交于 2019-11-28 01:07:14
问题 I an running this code: #!/usr/bin/python coding=utf8 # test.py = to demo fault def loadFile(path): f = open(path,'r') text = f.read() return text if __name__ == '__main__': path = 'D:\work\Kindle\srcs\test1.html' document = loadFile(path) print len(document) It gives me a trackback D:\work\Kindle\Tests>python.exe test.py Traceback (most recent call last): File "test.py", line 11, in <module> document = loadFile(path) File "test.py", line 5, in loadFile f = open(path,'r') IOError: [Errno 22]

How can I open files relative to my GOPATH?

て烟熏妆下的殇ゞ 提交于 2019-11-27 19:57:25
I'm using io/ioutil to read a small text file: fileBytes, err := ioutil.ReadFile("/absolute/path/to/file.txt") And that works fine, but this isn't exactly portable. In my case, the files I want to open are in my GOPATH, for example: /Users/matt/Dev/go/src/github.com/mholt/mypackage/data/file.txt Since the data folder rides right alongside the source code, I'd love to just specify the relative path: data/file.txt But then I get this error: panic: open data/file.txt: no such file or directory How can I open files using their relative path, especially if they live alongside my Go code? ( Note

Is there a convenient way to map a file uri to os.path?

筅森魡賤 提交于 2019-11-27 13:39:55
问题 A subsystem which I have no control over insists on providing filesystem paths in the form of a uri. Is there a python module/function which can convert this path into the appropriate form expected by the filesystem in a platform independent manner? 回答1: The urlparse module provides the path from the URI: import os, urlparse p = urlparse.urlparse('file://C:/test/doc.txt') finalPath = os.path.abspath(os.path.join(p.netloc, p.path)) 回答2: For future readers. The solution from @Jakob Bowyer doesn

What does the /private prefix on an iOS file path indicate?

扶醉桌前 提交于 2019-11-27 13:30:43
问题 I have a bug when my app runs on the iPhone but not when it runs on the simulator. I was using the length of the home directory path to extract the relative path of a file in /Documents. Unfortunately this doesn't always work correctly on the iPhone because the prefix "/private" is being added to the home path. However, with or without the prefix, the same file is referenced ok. The following code demonstrates this inconsistency. What is the purpose of "/private" and when is it supplied by

Java : File.toURI().toURL() on Windows file

我们两清 提交于 2019-11-27 13:02:09
问题 The system I'm running on is Windows XP, with JRE 1.6. I do this : public static void main(String[] args) { try { System.out.println(new File("C:\\test a.xml").toURI().toURL()); } catch (Exception e) { e.printStackTrace(); } } and I get this : file:/C:/test%20a.xml How come the given URL doesn't have two slashes before the C: ? I expected file://C:... . Is it normal behaviour? EDIT : From Java source code : java.net.URLStreamHandler.toExternalForm(URL) result.append(":"); if (u.getAuthority()

Unable to locate files with long names on Windows with Python

此生再无相见时 提交于 2019-11-27 12:49:11
问题 I need to walk through folders with long file names in Windows. I tried using os.listdir() , but it crashes with long pathnames, which is bad. I tried using os.walk() , but it ignores the pathnames longer than ~256, which is worse. I tried the magic word workaround described here, but it only works with mapped drives, not with UNC pathnames. Here is an example with short pathnames, that shows that UNC pathnames don't work with the magic word trick. >>> os.listdir('c:\\drivers') ['nusb3hub.cat

accessing a file using [NSBundle mainBundle] pathForResource: ofType:inDirectory:

送分小仙女□ 提交于 2019-11-27 10:44:30
I have a file paylines.txt added inside the folder named TextFiles which resides inside the Resources folder of my iOS project in Xcode. This is the code I use to access the file: NSString* filePath = [[NSBundle mainBundle] pathForResource:@"paylines" ofType:@"txt" inDirectory:@"TextFiles"]; NSLog(@"\n\nthe string %@",filePath); The code prints: 2011-06-07 14:47:16.251 slots2[708:207] the string (null) I was also having the same problem. The Solution i found is ( in xcode 4.x): Go to : Target -> "Build Phases" -> "copy bundle Resources" Then add that particular file here. If that file is

How to get the file path in html <input type=“file”> in PHP?

泪湿孤枕 提交于 2019-11-27 09:44:27
Can somebody pls tell me how to get the filepath using html <input type="file"> in PHP? Here are my codes: index.php <form action="csv_to_database.php" method="get" > <input type="file" name="csv_file" /> <input type="submit" name="upload" value="Upload" /> </form> and in csv_to_database.php <?php if (isset($_GET['csv_file'])) { $row = 1; if (($handle = fopen($_GET['csv_file'], "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } }