filepath

How to get Desktop location?

一个人想着一个人 提交于 2019-11-28 20:53:08
I'm using Python on Windows and I want a part of my script to copy a file from a certain directory (I know its path) to the Desktop. I used this: shutil.copy(txtName, '%HOMEPATH%/desktop') While txtName is the txt File's name (with full path). I get the error: IOError: [Errno 2] No such file or directory: '%HOMEPATH%/DESKTOP' Any help? I want the script to work on any computer. tpearse You can use os.environ["HOMEPATH"] to get the path. Right now it's literally trying to find %HOMEPATH%/Desktop without substituting the actual path. Maybe something like: shutil.copy(txtName, os.path.join(os

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

爷,独闯天下 提交于 2019-11-28 20:38:39
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() != null && u.getAuthority().length() > 0) { result.append("//"); result.append(u.getAuthority()); } It

Load an image to UIImage from a file path to the asset library

笑着哭i 提交于 2019-11-28 20:28:55
Related to my previous question here . I have a path to an image in the asset library , for example: assets-library://asset/asset.JPG?id=1000000001&ext=JPG Now, how could I load the image from this path to a UIImage object? Here is the code: NSString *path = [occasion imagePath]; //temp NSLog(@"the 2nd occasion imagePath is: %@", path); //end if (path != nil) { //UIImage *image = [UIImage imageNamed:path]; UIImage *image = [UIImage imageWithContentsOfFile:path]; image = [image imageByScalingAndCroppingForSize:CGSizeMake(36.0, 42.0)]; [[cell imageView] setImage:image]; } from the answer linked

Unable to locate files with long names on Windows with Python

痞子三分冷 提交于 2019-11-28 20:14:00
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', 'nusb3hub.inf', 'nusb3hub.sys', 'nusb3xhc.cat', 'nusb3xhc.inf', 'nusb3xhc.sys'] >>> os.listdir('\\

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

我与影子孤独终老i 提交于 2019-11-28 16:53:53
问题 I need to extract the name of the parent directory of a certain path. This is what it looks like: c:\stuff\directory_i_need\subdir\file I am modifying the content of the "file" with something that uses the directory_i_need name in it (not the path). I have created a function that will give me a list of all the files, and then... for path in file_list: #directory_name = os.path.dirname(path) # this is not what I need, that's why it is commented directories, files = path.split('\\') line

android drawable from file path

社会主义新天地 提交于 2019-11-28 16:40:09
I have a file path String of the form "e:\...\xxx.jpg" How do I create a drawable from it? You can create a Drawable or Bitmap from a string path like this: String pathName = "/path/to/file/xxx.jpg"; Drawable d = Drawable.createFromPath(pathName); For a Bitmap: String pathName = "/path/to/file/xxx.jpg"; bitmap b = BitmapFactory.decodeFile(pathName); 来源: https://stackoverflow.com/questions/5834221/android-drawable-from-file-path

Is there a way of making strings file-path safe in c#?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 16:27:44
My program will take arbitrary strings from the internet and use them for file names. Is there a simple way to remove the bad characters from these strings or do I need to write a custom function for this? Jonathan Allen Ugh, I hate it when people try to guess at which characters are valid. Besides being completely non-portable (always thinking about Mono), both of the earlier comments missed more 25 invalid characters. 'Clean just a filename Dim filename As String = "salmnas dlajhdla kjha;dmas'lkasn" For Each c In IO.Path.GetInvalidFileNameChars filename = filename.Replace(c, "") Next 'See

Can't find my package path in file explorer

别等时光非礼了梦想. 提交于 2019-11-28 14:37:25
My project package doesn't show in DDMS > File Explorer (I had selected my phone in window devices). I found that an error is shown in logcat, which says can't open file for reading. Is it possible that I didn't install Eclipse properly? Before that, my project ran well and I could see the project path in the file explorer (under data>data>). After I had make few changes (I don't recall what changes I had made, too many), when doing another project, I uninstalled and reinstalled Eclipse, then this error appeared. I can't find ALL my project package in file explorer. May I know what is the

How do I resolve a relative path to an absolute path in C?

余生长醉 提交于 2019-11-28 12:21:48
I have a C console app where I need to output the absolute path to a file given a (possibly) relative path. What is the best way to do this in C in a Windows environment? I think you are looking for _fullpath() . nullpotent GetFullPathName should help you on Windows. GetFullPathName merges the name of the current drive and directory with a specified file name to determine the full path and file name of a specified file. 来源: https://stackoverflow.com/questions/8354422/how-do-i-resolve-a-relative-path-to-an-absolute-path-in-c

File path or file location for Java - new file()

陌路散爱 提交于 2019-11-28 12:07:30
I have the following structure for my project. In Eclipse: myPorjectName src com.example.myproject a.java com.example.myproject.data b.xml In a.java , I want to read b.xml file. How can I do that? Specifically, in a.java , I used the following code: DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse (new File("data/b.xml")); This code cannot find b.xml . However, if I change the path to src/com/example/myproject/data/b.xml then it works. The current location seems