I was wondering if using:  System.getProperty("user.dir");   to get the absolute path of a folder is the best way to go about it? I am looking to pass my application onto other computers and I need a full proof way of getting the 'home' directory so that I can just add onto the path when I need to use other folders by just doing:  String path = System.getProperty("user.dir"); String otherFolder = path + "\\other";
23794
The difficulty is that it should be cross platform. Windows 2000, XP, Vista, OSX, Linux, other unix variants. I am looking for a snippet of code that can accomplish this for all platforms, and a way to detect the platform.  Now, you should be aware of  that user.home does not work correctly, so please do not provide me of textbook answers, I can find these myself in the manuals.
7642
I have a program which I am trying to run, however when I run it; it just complains that it can't find a particular file.  However I have no idea which folder it is trying to find this particular file in. I have a copy of the required file, I just need to know which folder to copy it too.  Is there any way to show in real time which files are being accessed or which files are trying and failing to be accessed?  I am using Ext4 filesystem if that helps.  Thanks
67491
System.IO.Directory.GetFiles() returns a string[].  What is the default sort order for the returned values?  I'm assuming by name, but if so how much does the current culture effect it?  Can you change it to something like creation date?   Update: MSDN points out that the sort order is not guaranteed for .Net 3.5, but the 2.0 version of the page doesn't say anything at all and neither page will help you sort by things like creation or modification time.  That information is lost once you have the array (it contains only strings).  I could build a comparer that would check for each file it gets, but that means accessing the file system repeatedly when presumably the .GetFiles() method already does this.  Seems very inefficient.
29814
Is there a way through the .net framework to determine if a folder is shared or not?  Neither Diretory, DirectoryInfo or FileAttributes seem to have any corresponding field.  One thing I forgot to mention was that I want to be checking for network shares.  But I'll investigate the WMI stuff.
47343
Given a path such as "mydir/myfile.txt", how do I find the file's absolute path relative to the current working directory in Python? E.g. on Windows, I might end up with:  "C:/example/cwd/mydir/myfile.txt"
57967
I'm using Ubuntu 14.04 LTS a little while and I consider myself a beginner.  I am using the Nautilus file manager:    I wonder if you can navigate the folders through the directory tree, like in Windows through folders or the + sign.
34841
I've recently searched how I could get the application's directory in Java. I've finally found the answer but I've needed surprisingly long because searching for such a generic term isn't easy. I think it would be a good idea to compile a list of how to achieve this in multiple languages.  Feel free to up/downvote if you (don't) like the idea and please contribute if you like it.  Clarification:  There's a fine distinction between the directory that contains the executable file and the current working directory (given by pwd under Unix). I was originally interested in the former but feel free to post methods for determining the latter as well (clarifying which one you mean).
84929
If I do pwd I notice it uses whatever symlinks I used to get into the current directory.  Can I get it to tell me the "real" directory I'm in ... i.e. the path from the root to my current directory without the use of any symlinks?
1778
I have a script which sets some environment variable to paths:  export VAR1=/home/xyz/DIR_IN_WHICH_THIS_FILE_EXISTS  export VAR2=$VAR1/abc/qwe  ...   Can I use something to get the DIR_IN_WHICH_THIS_FILE_EXISTS so that if I run this script from anywhere(any path) in the machine, it would set the same values to VAR1 depend on in which directory the script exists?  Please help
40837
There is another question on here that allows users to find the path to their current background image through a cmd command.    In Windows 10 this no longer works. It only returns the first image in the folder, it does not change with the backgrounds as they transition. I need a similar command that returns the path(s) to the current image on the desktop background(s) that actually works in Windows 10 if one exists.
9932
My path is \\server\folderName1\another name\something\another folder\  How do I extract each folder name into a string if I don't know how many folders there are in the path and I don't know the folder names?  Many thanks
97765
In Linux, we have the "which" command to find out the path of an executable. What is its Windows equivalent? Is there any PowerShell command for doing that?
95118
The windows command line prompt display the full path of the currently directory, which will be too long when I am deep into a directory, like:  V:\Runtimes\ProjectName\src\ToolsTest\JavaCrashExample\JavaCrash\main\ToolsTest\JavaCrashExample\JavaCrash&gt;   Is their any way to customized this, so that I can just display the current directory's name?  Thanks.
106043
I have a C# application that scans a directory and gathers some information.  I would like to display the account name for each file.  I can do this on the local system by getting the SID for the FileInfo object, and then doing:  string GetNameFromSID( SecurityIdentifier sid ) {     NTAccount ntAccount = (NTAccount)sid.Translate( typeof( NTAccount ) );     return ntAccount.ToString(); }   However, this does not work for files on a network, presumably because the Translate() function only works with local user accounts.  I thought maybe I could do an LDAP lookup on the SID, so I tried the following:  string GetNameFromSID( SecurityIdentifier sid ) {     string str = "LDAP://&lt;SID=" + sid.Value + "&gt;";     DirectoryEntry dirEntry = new DirectoryEntry( str );     return dirEntry.Name; }   This seems like it will work, in that the access to "dirEntry.Name" hangs for a few seconds, as if it is going off and querying the network, but then it throws a System.Runtime.InteropServices.COMException  Does anyone know how I can get the account name of an arbitrary file or SID?  I don't know much about networking or LDAP or anything.  There's a class called DirectorySearcher that maybe I'm supposed to use, but it wants a domain name, and I don't know how to get that either - all I have is the path to the directory I'm scanning.  Thanks in advance.
17432
On the Windows platform, most large applications come with their own installer which sets up folders under C:\Program Files, possibly some other places, and perhaps adding some registry keys, etc.  But there's still quite a few tools around that consist of just an .exe or maybe also a README and a .dll or two.  How should I install such tools? Directly in C:\Program Files? All in one subfolder under C:\Program Files? Somewhere under C:\Users\Me? Somewhere totally different?  Or maybe different approaches for the tools with just an .exe to those that also have other files, or maybe only the ones with .dlls need to be treated differenty ...  Is there any standard accepted way to do this? A "best practice"? If the answer depends on the Windows version, I'm using Windows 7.  In particular, what might strike people as the obvious answer seems to have a catch:  I had tried to manually create new subfolders under C:\Program Files. In fact I thought I had done so before, but Windows puts up a dialog Destination Folder Access Denied. This caused me to think twice rather than just blindly click Continue.      On the assumption that greater minds than mine have come up against this many times over the years I'd like to ask the community if some kind of "best practice" has come to be accepted.
32014
There's a part in my apps that displays the file path loaded by the user through OpenFileDialog. It's taking up too much space to display the whole path, but I don't want to display only the filename as it might be ambiguous. So I would prefer to show the file path relative to the assembly/exe directory.  For example, the assembly resides at C:\Program Files\Dummy Folder\MyProgram and the file at C:\Program Files\Dummy Folder\MyProgram\Data\datafile1.dat then I would like it to show .\Data\datafile1.dat. If the file is in C:\Program Files\Dummy Folder\datafile1.dat, then I would want ..\datafile1.dat. But if the file is at the root directory or 1 directory below root, then display the full path.   What solution would you recommend? Regex?  Basically I want to display useful file path info without taking too much screen space.  EDIT: Just to clarify a little bit more. The purpose of this solution is to help user or myself knowing which file did I loaded last and roughly from which directory was it from. I'm using a readonly textbox to display the path. Most of the time, the file path is much longer than the display space of the textbox. The path is supposed to be informative but not important enough as to take up more screen space.  Alex Brault comment was good, so is Jonathan Leffler. The Win32 function provided by DavidK only help with part of the problem, not the whole of it, but thanks anyway. As for James Newton-King solution, I'll give it a try later when I'm free.
29144
Windows file system is case insensitive. How, given a file/folder name (e.g. "somefile"), I get the actual name of that file/folder (e.g. it should return "SomeFile" if Explorer displays it so)?  Some ways I know, all of which seem quite backwards:   Given the full path, search for each folder on the path (via FindFirstFile). This gives proper cased results of each folder. At the last step, search for the file itself. Get filename from handle (as in ). This requires opening a file, creating file mapping, getting it's name, parsing device names etc. Pretty convoluted. And it does not work for folders or zero-size files.   Am I missing some obvious WinAPI call? The simplest ones, like GetActualPathName() or GetFullPathName() return the name using casing that was passed in (e.g. returns "program files" if that was passed in, even if it should be "Program Files").  I'm looking for a native solution (not .NET one).