Active3 months ago
  1. Directory Path
  2. Windows Get File Path
  3. Windows 10 Find File Path
  4. Windows Get File Path Cmd

I need to use shortened path names for an application that I am using. For example I need C:PROGRA~1 as opposed to C:Program Files. The program can't handle spaces and won't accept quoted paths (e.g. 'C:Program Files').

The output is self-explanatory. Based on the output, using the canonical path is best suitable to avoid any issues because of relative paths. Also, note that the java file path methods don’t check if the file exists or not. How to Find a File's Path on Windows. This wikiHow teaches you how to find the full path to a file using Windows Search, File Explorer, or the Run command window.

If it helps, I am using Windows 7. I can get access to any version since XP, if necessary.

If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string The modifiers can be combined to get compound results:%dpI - expands%I to a drive letter and path only%nxI - expands%I to a file name and extension only%fsI - expands%I to a full path name with short. Each file and folder on your computer has a unique location, called a file path / folder path.No two files can have the same path. If you move a file to another folder that contains a file with the same name, you'll get the 'There is already a file with the same name in this location' warning.

Nathan
7454 gold badges9 silver badges29 bronze badges
somehumesomehume

10 Answers

Start, and type cmd in the run box. Start cmd, and use cd to get to the folder you are interested in:

Then

PaulPaul
50.1k14 gold badges124 silver badges153 bronze badges

Create a bat file in some convenient directorythen you could copy+paste the short path from that path.

You could just run command.com and keep doing cd commands to your current directory too.

In Windows batch scripts, %~s1 expands path parameters to short names. Create this batch file:

I called mine shortNamePath.cmd and call it like this:

Here's a version that uses the current directory if no parameter was supplied:

Directory Path

Called without parameters:

Using SET and a named variable

Windows Command Prompt has some conventions for handling variableswith spaces in their values that are somewhat hard to learn and understand,especially if you have a Unix background. You can do

(with no quotes), or

(note the non-intuitive placement of quotes); then

Scott
17.3k11 gold badges48 silver badges92 bronze badges
SSpokeSSpoke

The 'short name' is really the old DOS 8.3 naming convention, so all the directories will be the first 6 letters followed by ~1 assuming there is only one name that matches, for example:

here is the only exception

phuclv
12.4k7 gold badges51 silver badges107 bronze badges
freedenizenfreedenizen

Here is a one liner:

Breakdown:

  • cmd /c - Starts a new instance of the Windows command interpreter, carries out the command specified by string and then terminates
  • for %%parameter in (set) do command - Conditionally perform a command several times.
  • echo - Display messages on screen. @ symbol is the same as ECHO OFF applied to the current line only.
  • %~s - Expanded path contains short names only.

Sources:

phuclv
12.4k7 gold badges51 silver badges107 bronze badges
Ivan SchwarzIvan Schwarz

Similar to Ivan Schwartz's answer, you can replace 'C:Program Files' with %cd% to get current dir:

bertieb
5,99611 gold badges30 silver badges44 bronze badges
Eino MäkitaloEino Mäkitalo

I found very handy way to solve short pathname of current directory (or anything else) if you have Powershell installed.

Just open powershell in current dir

  • in cmd windows type powershell

  • if you have folder open in gui you can type cmd.exe or powershell.exe directly in address bar of folder.

Then give command

Origin of information: [https://gallery.technet.microsoft.com/scriptcenter/Get-ShortName-90a49303]

Eino MäkitaloEino Mäkitalo

Alternatively, you could use this awesome little tool called PathCopyCopy

In a few clicks, you can get the long and short path of literally any folder from the contextual menu, e.g:

Right-click in the destination folder => Path Copy => Short Path.

Done. It will be copied to your clipboard.

AsamoahAsamoah

I have installed node modules by running npm install on a boilerplate. While trying to delete those folders, windows does not allow us to delete them as path is too long to be able to handle.

After some of shallow research, I thought it would be right my own piece of code snippet to rename the folders from root to leaf so that it would throw any violation exception for this attempt as well.

It works for me. Following is the code for the C# project.

phuclv
12.4k7 gold badges51 silver badges107 bronze badges
AshokAshok

This is the easiest way I have used when dealing with files with spaces and this is accessible from file explorer too has all the same access privileges.

phuclv
12.4k7 gold badges51 silver badges107 bronze badges
Santhosh KumarSanthosh Kumar

Just replace the spaces with

The more you share it after you have added your link the more likes you will get organically. Facebook like software.

It's the way things are 'translated', and spaces go into %20.

If you really need alot, simply pop open your browser and type something like

user556501user556501

Not the answer you're looking for? Browse other questions tagged windows-7 or ask your own question.

Active10 months ago

I remembered that I used a tool called as where to find locations for any executable programs like this in a console:

Now I cannot find this tool. Not sure if Windows has a build-in tool to do that search?

Cfinley
1,4333 gold badges12 silver badges20 bronze badges
David.Chu.caDavid.Chu.ca
1,4397 gold badges25 silver badges36 bronze badges

10 Answers

I think you may be thinking of the which command in Linux.

I'm not aware of an equivalent tool in Windows.

EDIT: I just remembered that there's a package called Unix Utils for Windows that would provide this functionality for you.

djhowelldjhowell
3,6911 gold badge16 silver badges20 bronze badges

According to the StackOverflow answer at Is there an equivalent of 'which' on windows?, where.exe does this on Windows 7 and Windows Server 2003 and later:

Example

Windows Get File Path

Output:

Community
Simon DSimon D
3,5732 gold badges12 silver badges14 bronze badges

EDIT: I should have added, if you can't use the WHERE command from the command prompt, check your PATH variable. (Just use the 'path' command.) Make sure C:WindowsSystem32 is in your path. That's where 'where.exe' is located.

WHERE is the command you're looking for! WHERE is like a cross between the UNIX shell built-in 'which' and the 'locate' command, in that it works for both command executables and regular files.

It's also somewhat more complex than either of those two, although, in general a simple

will work.

It's different from the 'locate' command in that it's not looking through the entire filesystem. Instead, the default behavior is to look for files in two locations:

  • The current directory.
  • All of the directories in the PATH variable.

So, any command that you can run directly from a command prompt without specifying the directory, will be found by the WHERE command. (Because any command like that is already in the PATH variable list.)

If you want to search only in the command path variable, you can use:

If, on the other hand, you want to find all copies of a file in a directory tree, you can use:

Finally, WHERE will find commands and any files with an extension from the PATHEXT variable without including the extension. All other files have to be specified either exactly or with wildcards.

Take for example the files 'dxdiag.exe' and 'dxdiagn.dll'. Note the following command and its output:

It succeeds in returning all versions of 'dxdiag.exe' because '.exe' is one of the extensions in the PATHEXT variable. (Note: 'WHERE dxdiag' would have worked as well, because C:WindowsSystem32 is in the PATH variable.)

on the other hand, fails to return any result, because '.dll' is not in PATHEXT.

In this case, look at the result that adding a wildcard gives us:

It successfully returns all versions of dxdiagn.dll.

For more information, use 'WHERE /?'. Hope this helps!

geogeo

use dir:

the cd part changes you to the root of the drive, to ensure searching starts at the top of the hierarchy.

John TJohn T
147k22 gold badges305 silver badges335 bronze badges

Note that some things might be a little different for PowerShell:

Rob JensRob Jens

Frustrating that it's not built-in as a simple command.

Windows Get File Path

However, there are several solutions, one of which is a batch file.

Create a batch file (which.bat) as follows:

This looks in the local directory, will take a filename parameter with or without an extension, and return the first match from the current directory or in the PATH.

Then run it like which cmd.exe to find the cmd.exe that will execute if you type in cmd.

b wb w

Windows 10 Find File Path

2,1444 gold badges24 silver badges30 bronze badges

On windows you can use the free utility Everything search engine to search instantly for any file by full or partial name (if your hard disk is formatted in ntfs).

harrymcharrymc
287k16 gold badges307 silver badges623 bronze badges

If you just want which, the GnuWin32 project has a bunch of unix utils with individual installers.

Justin LoveJustin Love
7162 gold badges19 silver badges35 bronze badges

In PowerShell

Windows Get File Path

You can easily convert this into a Cmdlet.

Another way to accomplish this, as suggested in an edit:

AnupamAnupam

If you just need the path to launch it, it's often better to use the start command. For example, you can use 'start chrome.exe' to start Chrom{e ium}, regardless of where it is installed.

Anonymous CowardAnonymous Coward

Windows Get File Path Cmd

Not the answer you're looking for? Browse other questions tagged windows or ask your own question.