filepath

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

耗尽温柔 提交于 2019-11-27 09:43:11
问题 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? 回答1: 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"

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

隐身守侯 提交于 2019-11-27 09:11:23
I need to know which is the real path of a given path. For example: The real path is: d:\src\File.txt And the user give me: D:\src\file.txt I need as a result: d:\src\File.txt 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

How can one get an absolute or normalized file path in .NET?

≡放荡痞女 提交于 2019-11-27 09:11:13
How can one with minimal effort (using some already existing facility, if possible) convert paths like c:\aaa\bbb\..\ccc to c:\aaa\ccc ? Path.GetFullPath perhaps? I would write it like this: public static string NormalizePath(string path) { return Path.GetFullPath(new Uri(path).LocalPath) .TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) .ToUpperInvariant(); } This should handle few scenarios like uri and potential escaped characters in it, like file:///C:/Test%20Project.exe -> C:\TEST PROJECT.EXE path segments specified by dots to denote current or parent directory c:\aaa

“invalid path 0 files copied” Error while using xcopy command

馋奶兔 提交于 2019-11-27 08:21:39
Hi I have this little command to copy files in a batch, which will help because I do this specific copy multiple times a day. The problem occurs while using the xcopy command. Everything is in order, but I am receiving this error: "Invalid path 0 files copied". Here is the code: C:\Windows\System32\xcopy /Y "C:\Users\Ryan\Desktop\mmars_pub\" "C:\Users\Ryan\Desktop\Dropbox\MMARS\mmars_pub\" I'm using the full path to the xcopy executable because I was having trouble configuring the path environment variable to function properly. I would imagine that it shouldn't affect the result though. I read

How can I get the last folder from a path string?

别等时光非礼了梦想. 提交于 2019-11-27 07:34:58
问题 I have a directory that looks something like this: C:\Users\me\Projects\ In my application, I append to that path a given project name: C:\Users\me\Projects\myProject After, I want to be able to pass that into a method. Inside this method I would also like to use the project name. What is the best way to parse the path string to get the last folder name? I know a work-around would be to pass the path and the project name into the function, but I was hoping I could limit it to one parameter.

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 06:57:11
问题 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? 回答1: I think you are looking for _fullpath(). 回答2: 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

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

橙三吉。 提交于 2019-11-27 06:04:16
问题 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,

Document directory path change when rebuild application

独自空忆成欢 提交于 2019-11-27 06:03:23
问题 I download the video file from url and save it in document directory with this path: let destination: DownloadRequest.DownloadFileDestination = { _, _ in let pathComponent = "pack\(self.packID)-\(selectRow + 1).mp4" let directoryURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] let folderPath: URL = directoryURL.appendingPathComponent("Downloads", isDirectory: true) let fileURL: URL = folderPath.appendingPathComponent(pathComponent) return (fileURL, [

How to get the file path from URI? [duplicate]

独自空忆成欢 提交于 2019-11-27 05:39:05
问题 This question already has answers here : Get filename and path from URI from mediastore (25 answers) Closed 6 years ago . Please find my code below. I need to get the file path of the pdf document, selected by the user from SDcard. The issue is that the URI.getPath() returns: /file:///mnt/sdcard/my%20Report.pdf/my Report.pdf The correct path is : /sdcard/my Report.pdf Please note that i searched on stackoverflow but found the example of getting the filePath of image or video, there is no

Write a file in a specific path in C++

谁都会走 提交于 2019-11-27 05:07:21
I have this code that writes successfully a file: ofstream outfile (path); outfile.write(buffer,size); outfile.flush(); outfile.close(); buffer and size are ok in the rest of code. How is possible put the file in a specific path? Specify the full path in the constructor of the stream, this can be an absolute path or a relative path. (relative to where the program is run from. The the streams destructor close the file for you, explicit closes are MORE likely to introduce bugs (writing to after the file is close). #include <fstream> #include <string> int main() { const char *path="/home/user