filepath

Visual Studio - Unit tests loading resources in the project

橙三吉。 提交于 2019-11-29 11:03:07
问题 The goal is to run some tests given some data in those Xml files. How would you easily load a given Xml file into an XmlDoc within the unit test methods? Current state is: XmlDocument doc = new XmlDocument(); string xmlFile = "4.xml"; string dir = System.IO.Directory.GetCurrentDirectory() + @"\Msgs\" //dir is then the value of the current exe's path, which is //d:\sourcecode\myproject\TestResults\myComputer 2009-10-08 16_07_45\Out //we actually need: //d:\sourcecode\myproject\Msgs\ doc.Load(

Get the filePath from Filename using Java

冷暖自知 提交于 2019-11-29 10:52:48
Is there a easy way to get the filePath provided I know the Filename? You can use the Path api: Path p = Paths.get(yourFileNameUri); Path folder = p.getParent(); Look at the methods in the java.io.File class : File file = new File("yourfileName"); String path = file.getAbsolutePath(); I'm not sure I understand you completely, but if you wish to get the absolute file path provided that you know the relative file name, you can always do this: System.out.println("File path: " + new File("Your file name").getAbsolutePath()); The File class has several more methods you might find useful. Correct

Splitting path strings into drive, path and file name parts

主宰稳场 提交于 2019-11-29 09:12:41
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 %s and file is %s' % (drive, path, file)) I get the following error: File "C:/Users/visc/scratch

Determining location of JVM executable during runtime

北城以北 提交于 2019-11-29 09:11:15
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 independent, because the Windows executable's name is java.exe , not java . Is there a way to get the path

Strange path separators on Windows

时光总嘲笑我的痴心妄想 提交于 2019-11-29 07:39:32
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] invalid mode ('r') or filename: 'D:\\work\\Kindle\\srcs\test1.html' D:\work\Kindle\Tests> If I change

File path for AJAX script (in Wordpress)

牧云@^-^@ 提交于 2019-11-29 06:29:43
I use this jquery-ajax script to send email: $.ajax({ url: process.php, type: "POST", data: data, cache: false, ... in url I call the php file that sends email, but ajax get it only if I specify the full path: url: "http://www.domain.com/wp-content/themes/site_theme/templates/process.php", but I have to use a syntax like this: url: "../../templates/process.php", or using a variable to declare in the html header/footer Html <script type="text/javascript"> var urlMail = '<?php bloginfo('template_url'); ?>/templates/process.php'; </script> Script url: "../../templates/process.php", but with both

Calculate relative Filepath [duplicate]

巧了我就是萌 提交于 2019-11-29 06:07:01
问题 This question already has an answer here: How to get relative path from absolute path 23 answers I have 2 Files: C:\Program Files\MyApp\images\image.png C:\Users\Steve\media.jpg Now i want to calculate the File-Path of File 2 (media.jpg) relative to File 1: ..\..\..\Users\Steve\ Is there a built-in function in .NET to do this? 回答1: Use: var s1 = @"C:\Users\Steve\media.jpg"; var s2 = @"C:\Program Files\MyApp\images\image.png"; var uri = new Uri(s2); var result = uri.MakeRelativeUri(new Uri(s1)

Run a script in the same directory as the current script

a 夏天 提交于 2019-11-29 04:39:54
问题 I have two Bash scripts in the same folder (saved somewhere by the user who downloads the entire repository): script.sh is run by the user helper.sh is required and run by script.sh The two scripts should be in the same directory. I need the first script to call the second one, but there are two problems: Knowing the current working directory is useless to me, because I don't know how the user is executing the first script (could be with /usr/bin/script.sh , with ./script.sh , or it could be

How to import files in python using sys.path.append?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 00:03:24
There are two directories on my desktop, DIR1 and DIR2 which contain the following files: DIR1: file1.py DIR2: file2.py myfile.txt The files contain the following: file1.py import sys sys.path.append('.') sys.path.append('../DIR2') import file2 file2.py import sys sys.path.append( '.' ) sys.path.append( '../DIR2' ) MY_FILE = "myfile.txt" myfile = open(MY_FILE) myfile.txt some text Now, there are two scenarios. The first works, the second gives an error. Scenario 1 I cd into DIR2 and run file2.py and it runs no problem. Scenario 2 I cd into DIR1 and run file1.py and it throws an error:

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

时光总嘲笑我的痴心妄想 提交于 2019-11-28 21:08:08
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 iOS? - (IBAction)testHomepath:(id)sender { NSFileManager *fmgr = [NSFileManager defaultManager]; NSString