Change Directory - Select a Folder (and drive)

CHDIR is a synonym for CD.

Tab Completion

Tab completion allows changing the current folder by entering just part of the path and pressing TAB. C:> CD Prog [PRESS TAB] Will go to C:\Program Files\ Tab Completion is disabled by default, it has been known to create difficulty when using a batch script to process text files that contain TAB characters. Tab Completion is turned on by setting the registry value shown below: REGEDIT4 [HKEY_CURRENT_USER\Software\Microsoft\Command Processor] "CompletionChar"=dword:00000009

A Current Directory for each drive?

Originally in MS-DOS, each drive had its own current directory, for complex historical reasons . Now in Win32, there is one global current directory, but at the command line the appearance is still maintained that each drive has its own current directory, this is a fake-out by cmd.exe. The location for each drive is stored using the undocumented environment variables =A: , =B: , =C: etc. The only reason you need to be aware of this is that GUI Windows applications may have a different current directory than the command prompt. Similarly two CMD sessions can each have a different current directory.

Errorlevels

If the Current directory was changed: %ERRORLEVEL% = 0 If the Directory does not exist or is not accessible or if a bad switch given: %ERRORLEVEL% = 1

CHDIR is a synonym for CD

CD is an internal command.

Change to the parent directory:

C:\Work> CD ..

Change to the grant-parent directory:

C:\Work\backup\January> CD ..\..

Change to the ROOT directory:

C:\Work\backup\January> CD \

Display the current directory in the specified drive:

C:\> CD D:

Display the current drive and directory:

C:\Work> CD
C:\Work> ECHO "%CD%"

In a batch file to display the location of the batch script file (%0) :

C:\> ECHO "%~dp0"

In a batch file to CD to the location of the batch script file (%0):

C:\> CD /d "%~dp0"

Move down the folder tree with a full path reference to the ROOT folder:

C:\windows> CD \ windows\java C:\windows\java>

Move down the folder tree with a reference RELATIVE to the current folder:

C:\windows> CD java C:\windows\java>

Move up and down the folder tree in one command:

C:\windows\java> CD ..\system32 C:\windows\system32>

Change the Current Drive , Enter the drive letter followed by a colon:

C:> E: E:>

To change drive and directory at the same time:

C:> cd /D E:\utils E:\utils\>

If Command Extensions are enabled, which they are by default, the CD command is enhanced as follows:

The current directory string is not CASE sensitive. So CD C:\wiNdoWs will set the current directory to C:\Windows CD does not treat spaces as delimiters, so it is possible to CD into a subfolder name that contains a space without surrounding the name with quotes. For example: cd \My folder is the same as: cd "\My folder" An asterisk can be used to complete a folder name: e.g. C:> CD pro* will move to C:\Program Files\

“Change is the law of life. And those who look only to the past or the present are certain to miss the future” ~ John F. Kennedy

Related commands

MD - Create Directory. pushd - Change Directory. RD - Delete directory or entire directory tree. How-to: Long filenames, NTFS and legal filename characters . Q156276 - Cmd does not support UNC names as the current directory. Equivalent PowerShell: Set-Location - Set the current working location. Equivalent bash command (Linux): cd - Change Directory.

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Change a drive letter

  • 4 contributors
Applies To: Windows 11, Windows 10, Windows Server 2022, Windows Server 2019, and Windows Server 2016

If you want to change a drive letter assigned to a drive, or you have a drive that doesn't yet have a drive letter, use Disk Management to change it. You can also mount the drive in an empty folder so that it appears as a folder. For more information, see Mount a drive in a folder .

If you change the drive letter of a drive that already contains Windows or apps, apps might have trouble running or finding the drive. We suggest not changing the drive letter of a drive that already contains Windows or apps.

The following steps show how to change the drive letter.

Open Disk Management with administrator permissions.

In Disk Management, select and hold (or right-click) the volume on which you want to change or add a drive letter and select Change Drive Letter and Paths .

Screenshot showing the Disk Management window with the Change Drive Letter and Paths feature selected.

If you don't see the Change Drive Letter and Paths option or it's grayed out, the volume either isn't ready to receive a drive letter or it's unallocated and needs to be initialized . It might also be that the drive isn't accessible, which is the case with EFI system partitions and recovery partitions. If you've confirmed that your volume is formatted with a drive letter that you can access but you're still unable to change it, that's beyond the scope of this article. We suggest contacting Microsoft Support or the manufacturer of your PC for more help.

To change the drive letter, select Change . To add a drive letter if the drive doesn't already have one, select Add .

Screenshot of the Change Drive Letter and Paths dialog.

Select the new drive letter and choose OK . Then select Yes when prompted about how programs that rely on the drive letter might not run correctly.

Screenshot of the Change Drive Letter or Path dialog that shows how to assign a new drive letter.

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback .

Submit and view feedback for

Additional resources

How to assign permanent letters to drives on Windows 10

You can assign drive letters manually, and in this guide, we show you how on Windows 10.

change drive letter batch

On Windows 10, when connecting a removable storage device or an internal hard drive, the system detects and assigns a drive letter automatically to make it usable. However, when reconnecting an external drive (such as a USB flash drive or SD or microSD cards), the system can end up assigning a different letter, which can be annoying.

If you want to see the same drive letter on a particular device, you can manually assign a permanent letter to any drive connected to your computer, and on Windows 10 , you can do this in at least three different ways, using Disk Management, Command Prompt, or PowerShell.

Using this approach will prevent Windows 10 from assigning a new letter or trying to set a letter already in use, which can cause conflicts. Also, it helps to select a drive letter that makes more sense to you.

In this Windows 10 guide, we walk you through several methods to manually assign a permanent letter to a drive, as long as you're connecting the drive to the same device and the letter isn't already in use.

How to assign a drive letter using Disk Management

How to assign a drive letter using command prompt, how to assign a drive letter using powershell.

To manage drive letters with the Disk Management tool, use these steps:

  • Open Start .
  • Search for Create and format hard disk partitions and click the top result to open the Disk Management experience.
  • Right-click the drive and select the Change Drive Letter and Paths option.

change drive letter batch

  • Click the Change button.

change drive letter batch

  • Select the Assign the following drive letter option.
  • Use the drop-down menu to assign a new drive letter. Quick tip: To avoid the system trying to assign the same letter to another drive, it's a good idea to start adding letters in backward order. For instance, instead of using D, E or F, it better to start with Z, Y or X when assigning a new letter.

change drive letter batch

  • Click the OK button.
  • Click the OK button again.

Once you complete these steps, the drive will permanently retain the assigned letter, even after reconnecting it. However, if you connect the drive to another device, it may receive a different letter.

While the easiest way to assign a new drive letter is to use Disk Management, you can also use DiskPart in Command Prompt to perform the same task.

Get the Windows Central Newsletter

All the latest news, reviews, and guides for Windows and Xbox diehards.

To assign a drive letter using Command Prompt, use these steps:

  • Search for Command Prompt , right-click the result, and then select the Run as administrator option.
  • Type the following command to start DiskPart and press Enter : diskpart
  • Type the following command to list all the available volumes and press Enter : list volume
  • Type the following command to select the volume (drive) to assign a new letter and press Enter: select volume 3 In the command, make sure to change "3" to the number that represents the drive on your device.
  • Type the following command to assign a new drive letter, and press Enter : assign letter=Z The command assigns the letter "Z" to the drive assuming it's available. However, you need to make sure to change the letter for the one that you want to use.

change drive letter batch

After completing these steps, similar to Disk Management, every time you reconnect the storage to the same device, Windows 10 should assign the same letter automatically.

Alternatively, you can also use PowerShell to change a drive letter on Windows 10 using these steps:

  • Search for PowerShell , right-click the result, and then select the Run as administrator option.
  • Type the following command to list the available drives and press Enter : Get-Disk
  • Type the following command to assign a permanent letter to the drive and press Enter : Get-Partition -DiskNumber 1 | Set-Partition -NewDriveLetter Z In the command, make sure to change "1" to the number that represents the drive that you want to modify, and change "Z" for the new letter that you want to use.

change drive letter batch

Once you complete the steps, the drive will be accessible through File Explorer using the letter that you assigned, and Windows 10 won't try to change it.

Updated March 7, 2019: We revised this guide to make sure it's current with the latest version of Windows 10.

More Windows 10 resources

For more helpful articles, coverage, and answers to common questions about Windows 10, visit the following resources:

  • Windows 10 on Windows Central – All you need to know
  • Windows 10 help, tips, and tricks
  • Windows 10 forums on Windows Central

Mauro Huculak

Mauro Huculak is technical writer for WindowsCentral.com. His primary focus is to write comprehensive how-tos to help users get the most out of Windows 10 and its many related technologies. He has an IT background with professional certifications from Microsoft, Cisco, and CompTIA, and he's a recognized member of the Microsoft MVP community.

  • 2 Minecraft's April Fools' joke was so good, people are angry that it isn't real content
  • 3 Co-op horror game Content Warning launches on Steam for FREE (but only for 24 hours)
  • 4 Helldivers 2 boss says devs may make a critically important Galactic War mechanic easier to understand: "We are talking about making this more clear"
  • 5 Hollow Knight: Silksong FAQ — Xbox Game Pass, trailers, and everything you need to know

change drive letter batch

How-To Geek

How to change a drive letter on windows 10 or windows 11.

You can change your drive letters in Windows 10 and 11 using the Disk Management utility.

Quick Links

What changing a drive letter does, how to change a drive letter, how to fix programs broken by changing a drive letter.

Changing the letter of a drive is easy on Windows 10 and Windows 11, but you should do it as soon as you add the drive to prevent future hassles. Find out how to change a drive letter here.

Windows assigns drive letters alphabetically --- starting with C --- when they're initialized. If you want to change a drive letter, you should do it before you install anything on the drive. Changing a drive letter after programs are installed could break them since there will be references to an installation location that is no longer there.

Windows has gotten pretty smart about updating shortcuts so that programs work after changing a drive letter. Most of your applications' shortcuts will probably be automatically corrected. Unfortunately, Windows isn't as good about updating file associations. You'll have to manually set the default apps associated with files to fix file associations if they were broken by changing the drive letter.

It is possible to change the boot drive letter to something else, but we don't recommend it. Changing C:\ to another letter is likely to result in severe issues, like a PC that cannot boot into Windows at all. Even if it were able to boot, there would be a huge number of programs that would not be able to run.

Technically speaking, while they are commonly called drive letters, each letter actually refers to a partition on a disk. If you have multiple partitions on a single disk, you will need to assign a letter to each partition to make them all accessible. If a disk has just a single partition, it will just have a single letter pointing to that partition. (However, you do not have to assign a letter to each partition. Partitions without drive letters will not appear in File Explorer and elsewhere.)

Changing a drive letter is pretty simple. Click the Start button, type "Disk Management" in the search bar, and then hit Enter.

The program name displayed in the search will not be Disk Management. It will be "Create and format hard disk partitions."

You could also hit Windows+X or right-click the Start button, and then click "Disk Management."

Identify the drive you'd like to change in the Disk Management Window. In this example, we'll change the letter of the D:\ drive to J:\. You can right-click the drive on the text list, or on the menu below. Either works.

Select "Change Drive Letter and Paths" in the right-click menu that appears.

In the window that pops up, click "Change."

Select whatever letter you want from the drop-down menu. Then click "Ok."

Two popups will warn you about changing your drive letter. Click "Yes" on both of them, and then restart your computer.

Once Windows has restarted, the drive letter should be changed.

There are a few ways you can fix a program broken by changing the drive letter.

Fix The Shortcut

If you're lucky, the only thing that is broken is the shortcut. Fix a shortcut by right-clicking the shortcut on your desktop, and then click Properties.

You need to change the target of the shortcut to the new drive letter.

For example, if GIMP was previously installed at " D :\GIMP 2\bin\gimp-2.10.exe," and you changed the D drive to J, change the target of the shortcut to " J :\GIMP 2\bin\gimp-2.10.exe."

Finalize the change by clicking "Apply" and then "Ok."

Reinstall the Program

Reinstalling the program will generate new entries in the registry, so everything on the computer will know where to look for the program. Some installers won't like reinstalling directly over existing files, so you may need to rename or delete the old installation first.

Change the Drive Letter Back

If you changed the drive letter of a drive with a lot of programs installed, it might be easier to change the drive letter back. Changing the drive letter back should automatically fix any programs and file associations that were broken.

Edit the Registry

You can break programs, or even Windows itself, by editing the registry. Be careful, and learn about how to edit the registry before you try it. Make sure you backup the Windows registry first. You should not attempt this method unless you have no other options.

Windows, and a lot of programs, track where programs are installed via the Windows registry. It is possible to manually adjust the registry to fix broken programs. Keep in mind that there could be dozens of registry entries you need to edit. A program like GIMP can have registry entries for the context menu, for the "Open With" menu, for any file associations, and for the location of its executables. Other programs may only have a few entries related to where it is installed.

If you're not deterred, here's how you do it.

First, you need to know where the program was previously installed. In this case, the program was installed to the "D:\GIMP 2" folder, and the executables were found the "D:\GIMP 2\bin" sub-folder. It is now located at "J:\GIMP 2" instead.

We need to update the registry to reflect the change in location. Click the Start button, type "regedit" into the search bar, right-click Regedit, and click "Run as administrator."

In Regedit, hit Ctrl+F to bring up a search window. Type in the old location for the program you're trying to fix --- "D:\GIMP 2" for our example --- then click "Find Next."

Once Regedit has found something with "D:\GIMP 2" as part of a path, it'll show it to you. Here is an example from the GIMP search.

To actually change them, double click the name of the registry entry you want to modify. Then change the drive letter to J, or whatever you chose. If you didn't otherwise move the folder, leave the rest of the path alone. Then click "Ok."

You'll need to repeat this multiple times. To find the next result using your search term, you can hit the F3 key. There will be a popup once you've found all of the entries.

Changing drive letters can be a simple way to customize your PC. Do it before you install anything on the drive, however. You'll prevent any problems before they occur, and probably save yourself quite a bit of troubleshooting.

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How to get a list of drive letters on a system through a windows shell (bat, cmd)?

How do I get a list of drive letters and their associated labels on a windows system through a bat file?

  • windows-command-prompt

Eduardo Ivanec's user avatar

14 Answers 14

This will get most of it:

If you have any drives mapped via subst you would also need to get those:

For completeness, you would do it like this in Powershell (if you are on windows 7 or have installed it):

You can also do it from the command prompt or a batch file using WMI like this:

Dennis Williamson's user avatar

  • 1 This doesn't list local disk drives like any internal hard drives or cdroms. Am I missing something? –  Chris Magnuson Sep 4, 2009 at 21:12
  • Nope, I misunderstood the question. I thought that you only wanted mapped drives. I will edit. –  EBGreen Sep 4, 2009 at 21:18
  • 2 The wmic solution should give you everything. –  EBGreen Sep 4, 2009 at 21:20
  • You need to remove the quotes from wmic logicaldisk get "caption,providername,drivetype" so that it is wmic logicaldisk get caption,providername,drivetype other wise it throws an error. EBGreen you have single handedly blown my mind for the day, I have never seen wmic even though I have been scripting various server builds for weeks and I am extremely excited to see what else I can do with it. Great job! –  Chris Magnuson Sep 4, 2009 at 21:24
  • 1 wmic logicaldisk get caption,providername,drivetype,volumename the VolumeName was what I was missing, if you update yours with that I will accept it as the answer. Thanks –  Chris Magnuson Sep 4, 2009 at 21:31

To use diskpart, there is no need to create an intermediate file. Try:

gnoise's user avatar

  • 2 This is the best answer and returns the most info about the mounted drives in a beautiful format. –  ekerner May 29, 2013 at 7:41
  • 1 but it requires admin rights –  LogicDaemon Mar 1, 2017 at 7:56

Fast, flexible and efficient. Although a little complex.

Dharma Leonardi's user avatar

  • I don't know what versions of Windows this works on but I just tested it on my Win 7 and XP machines and got the following output from both: ` DRIVE LETTER(s):USED: " =" DRIVE LETTER(s):FREE: "!TMP_FREE_DRIVE_LETTERS!"` –  John Gardeniers May 12, 2011 at 0:44
  • Sorry, you need to put this in the beginning of the batch file. setlocal enabledelayedexpansion –  Dharma Leonardi May 12, 2011 at 3:19
  • I've edited your answer to include the missing line. It works now. +1 –  John Gardeniers May 12, 2011 at 3:31

inspired by Scott

also shows CD drive letters and network mounted disk letters. No need to have admin rights.

Geoleven's user avatar

  • simple and works –  Tyler Liu Feb 27, 2013 at 10:13
  • "i was unexpected at this time." –  Berit Larsen Sep 7, 2015 at 9:05
  • @BeritLarsen you need to double up % symbols if running it as a batch file rather than on the command line. –  TessellatingHeckler Oct 26, 2016 at 0:02

If anyone is lucky enough to be using Vista (Vista Ultimate SP2 b6002, in my case) and the gwmi and wmic snippets given here don't work exactly, here is what I did to make it work.

For gwmi , if you receive no output, try changing the DriveType to 3. If still having problems, remove the -filter option altogether and analyze output.

For wmic , if you receive "Invalid GET Expression", then try putting the get expression in quotes:

tdowg1's user avatar

sample output

Jader Dias's user avatar

This site has a much simpler set of calls:

http://en.code-bude.net/2013/02/23/show-all-drives-in-command-prompt/

Show local drives:

wmic logicaldisk get deviceid, volumename, description

If you want to show only drives of a particular type, the wmic command can be further expanded to include a where clause.

wmic logicaldisk where drivetype=2 get deviceid, volumename, description

0 => Unknown

1 => No Root Directory

2 => Removable Disk

3 => Local Disk

4 => Network Drive

5 => Compact Disc

6 => RAM Disk

David Tr's user avatar

  • I tried this one and it didn't work. I think there needs to be a space in front of the /s but even with that change it didn't work. I put the above in a file, d.bat and I see the diskpart window flash up but then disappear and the cmd shell where I'm running this then shows the pause running. –  slm Dec 21, 2011 at 3:27

I found the diskpart approach reports DVD drives with no disc inserted, and doesn't report SD cards with valid drive volumes

jscott's user avatar

  • does not work for windows xp –  Tyler Liu Feb 27, 2013 at 10:15

pbies's user avatar

Somewhat kludgy, but works from a batch file:

Nexus's user avatar

Although it has enough answer, I'd like to add one when you want to use it in batch file. If you get "Invalid GET Expression", you could put a ^ before the ',', like below:

Mingjiang Shi's user avatar

  • What does this ^ do here? –  vonbrand Mar 27, 2013 at 10:10
  • It is cmd.exe's escape character, similar to \ in Unix like shells. –  gimpf May 12, 2013 at 11:39

Using wmic in a for loop to determine all the available drives.

There is also this little hack using exit codes 65 to 90 converted to ascii which will return all Alpabetical characters A to Z with all credit to Aacini.

Gerhard's user avatar

  • Um, wow. So if you can distill that into something that would actually just output the drive letters and labels that exist on the system that would be closer to the answer to the question though this is it least movement in the right direction. –  Chris Magnuson Sep 4, 2009 at 21:16
  • I'm getting down-voted for providing a solution that meets the criteria? Wow... –  Scott Sep 5, 2009 at 5:19
  • 4 Well, for one thing, it produces errors for drives that exist but contain no media, such as a CD/DVD drive. –  Dennis Williamson Sep 6, 2009 at 12:47

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged windows batch-file windows-command-prompt ..

  • The Overflow Blog
  • Will antitrust suits benefit developers?
  • Are long context windows the end of RAG?
  • Featured on Meta
  • New Focus Styles & Updated Styling for Button Groups
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network

Hot Network Questions

  • Is it appropriate to ask for a raise?
  • Add annotation to a table without changing the column width
  • Way to share code built on scripts with Creative Commons licence including no derivative clause?
  • What does "Funnies" refer to?
  • What is the History, Context, and Implications of the Term "Moonspeak"?
  • Will it be possible to prevent cancer by introducing ECC on genome?
  • Number operation problem - find minimum number of operations
  • How do I motivate my PhD students to attend seminars
  • Is it possible to have very different sea levels?
  • What was this television history series?
  • How will the world learn that Q-Day has arrived?
  • What's role of software verification in modern software engineering
  • Gravitational forces
  • What do you call a specific 'snapshot' of the way a group of levers, knobs, and buttons are set?
  • Temporarily replacing one pane of glass in a double-pane door
  • Feudali“zmie” or feudali“źmie”?
  • Sci-fi story about a boy living in a city that no one ever leaves, with robots and a master computer
  • How does a Linux operating system stand going back in time (when applying winter time for example)? Going back a second, would it be the same problem?
  • Life on a planet with never-ending rain
  • What were the most common software distribution formats for MacOS Classic?
  • You're at war with countries X and Y. Does international law say anything about bombing X's embassy in Y (to kill a high-value target)?
  • Did Esau ever “break Jacob's yoke from his neck”? (Genesis 27:40)
  • Why do we associate negative sign to electric charges when they are a scalar quantity?
  • Do creatures with a reach of 0 get attacks of opportunity when a foe moves away?

change drive letter batch

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How can I permanently assign drive letters to my USB devices in Windows?

I have several customers with different PCs (Windows XP, Windows Vista and Windows 7).

Unlike DOS 6.22, where you can permanently assign drive letter designations (e.g. Drive C: = Hard Disk Bootable Partition, Drive D: = CD Drive, or any additional partitions you want to create with FDISK, depending on which version of Windows you are running), if in Windows XP I connect a USB flash drive, it will assign it drive E:, in Windows Vista it will assign it drive F:.

In DOS 6.22, when you have LASTDRIVE=Z: in your CONFIG.SYS file, you can then statically assign permanent logical drive designations to any devices whether you connect them or not.

Why can't this be done in Windows? I have no way to create standardized backup PowerShell or batch file scripts!

Dennis's user avatar

  • Based on all the answers I've seen so far, there's no way to permanently reserve a logical drive letter for an external device in Windows!.. a flaw! –  Joe R. Jul 5, 2011 at 23:25
  • 1 The drive letter is stored in the windows registry, not on the device, windows looks at the device ID and checks the windows registry and assigns the drive letter based on that, if there is no pre assigned letter it will assign the first unused drive letter. so no way to do what you want from PC to PC other than assign the same drive letter for each device on each PC. It is always better to assign a letter farther down the alphabet, that way there are no collisions with drive letters already occupied on any given PC. –  Moab Jul 5, 2011 at 23:29
  • @Moab: I'll use your suggestion to assign an X: Y: or Z: although maybe I can devise a scheme to identify an attached device by volume label name. I think this is where Microsoft missed the boat with Windows!.. They used the same scheme used in DOS to identify devices whereas in UNIX everything, devices included, is a file in the filesystem, example: /dev/fd0 = diskette drive, /dev/hd0 = logical hard disk 0.. Now in Windows, we have floating (variable) logical devices besides all the other similarities with DOS, including security issues which have never been a problem with UNIX-bases systems! –  Joe R. Jul 5, 2011 at 23:51
  • Yup, Windows sucks, let us count the ways... –  Moab Jul 6, 2011 at 0:01

7 Answers 7

You can setup Windows so that it remembers the drive letter you asign to a drive, but you have to connect the device and set it up first. This can be done in the Control Panel > Administrative Tools > Computer Management (or run compmgmt.msc if you're as lazy as me). Under Storage > Disk Management , right-click on the drive you want to configure and select Change Drive Letter and Paths... . There you can change the drive letter that's assigned to the drive.

After this is done, whenever the drive is plugged back in, this letter will be used if it's available . If this is too risky for you, you can mount the drive in an empty folder anywhere on the filesystem instead (via the same interface). This works the same as the drive letter in the sense that Windows will only use it if it's available, but it will never do it unless it's explicitly setup to do so.

Martin Larente's user avatar

  • I think this is the best way to do it. Make sure to use higher drive letters so that other removable devices don't steal the next available driver letter and cause a conflict. –  Chris Thompson Jul 5, 2011 at 23:14
  • @Martin: You see?.. "...if it's available." meaning there's no way in Windows to guarantee that letter will be available if another device takes it, which in the real world, frequently happens! –  Joe R. Jul 5, 2011 at 23:21
  • 4 @Frank Computer: then you can use an empty directory to mount the device instead. It won't be used up by another drive unless it's manually configured that way. –  Martin Larente Jul 5, 2011 at 23:32
  • @Frank Computer: This is why you start your "static" drive letter assignments with Z: . If you have more than 20 different USB devices, you're in trouble no matter what you do. USBDLM works fairly well as @Mike Renfro mentions below. –  Bacon Bits Jul 6, 2011 at 4:47
  • I have found that even when I force assign the drive letter to my USB drive, that Windows 7 will often take that drive letter assignment and use it (or reserve it) after I have dismounted it. I normally want to assign my portable drive to G: at work. I unmount the drive and when I plug it back in the next day, Windows 7 often refuses to reassign it back to G:. It will instead assign it to H:. Even worse is that Windows 7 doesn't have G: available to be reassigned to. The logical drive letter is missing from the available list until I reboot - then I can force the assignment back to G:. –  John C Aug 16, 2016 at 15:43

Instead of trying to define a standard drive letter for your scripts, define an environment variable that you set on each system to designate the USB drive.

Mark Ransom's user avatar

  • or perhaps better to use volume name vs. drive letter? –  Joe R. Jul 5, 2011 at 23:45

One word: USBDLM .

  • automatically solves conflicts between USB drives and network or subst drives of the currently logged on user
  • you can define new default letters for any/all USB drives
  • you can make your 19-in-1 card reader only allocate drive letters for slots that have media inserted
  • usb port number
  • drive type (CD, removable, fixed)
  • presence of files/folders
  • volume label
  • volume serial number

32-bit and 64-bit versions available. This gets installed on each and every Windows system I install. No registry hackery, no disk management tool required, it just works as a persistent service. I cannot recommend this highly enough.

Mike Renfro's user avatar

Create your batch file scripts using %~d0 as the drive letter and colon. %~d0 is replaced by the drive containing the script. So if on one machine the thumb drive is F %~d0 is equivalent to F: On another machine the thumb drive is W %~d0 is equivalent to W:

All my scripts are this way because I use my thumb drive in 100s of machines

Kevin's user avatar

You can use also Disk Management (part of Computer Management) to give the volume a specific drive letter.

Neil's user avatar

Windows remembers drives based on an ID it gets from the drive itself. It tries to assign the original drive letter it first assigned it, but will assign another if that is in use. You can see Windows' memory of them in HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices (be very careful if you ever edit values under this key).

If you go into Computer Management (Control Panel > Administrative Tools > Computer Management, or just Run compmgmt.msc ) and select Disk Management, you will be able to set the drive letter there by right-clicking on the drive and selecting "Change Drive Letter and paths...". Once you have changed it, Windows will afterward attempt to re-use that drive letter when the recognized device is reconnected. You could use this to set the same drive letter for the device on each machine it will be used on.

Joel B Fant's user avatar

You could try using USBDeview .

Find the device in the list, right-click and choose Change Assigned Drive Letter, then set it to the letter you would prefer. If I remember correctly, it is persistant.

Gareth's user avatar

  • Doesn't work for me if Windows has taken and used my previous drive assignment (see my comments above), even when running as Admin. My drive will stay as H: if Windows decides has "taken" my previous G: letter. Only a reboot and a forced assignment will work for me. Reboot frees the "reserved" G: (in my case) and then I can reset and force my drive with Mini Tool back to G (with Admin rights). –  John C Aug 16, 2016 at 15:39

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged windows batch powershell ..

  • The Overflow Blog
  • Will antitrust suits benefit developers?
  • Are long context windows the end of RAG?
  • Featured on Meta
  • New Focus Styles & Updated Styling for Button Groups
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network
  • Google Cloud will be Sponsoring Super User SE

Hot Network Questions

  • How will the world learn that Q-Day has arrived?
  • Reversing the order of function arguments by a replacement rule
  • How does the sequence $C3, $C2, $CD translate to "CBM"?
  • Gravitational forces
  • Linden Mayer System with multiple symbols
  • How does a Linux operating system stand going back in time (when applying winter time for example)? Going back a second, would it be the same problem?
  • Why does my futuristic society want transparent iPads and computer monitors?
  • Why does my integrator slowly saturate to negative rail in the following configuration?
  • Number operation problem - find minimum number of operations
  • Temporarily replacing one pane of glass in a double-pane door
  • In The Martian, Mark keeps the largest potatoes for his food supply and replants the smaller ones. Doesn't this cultivate smaller potatoes?
  • One within the other
  • Does the "gradual brain replacement" thought experiment prove consciousness is independent of substrate?
  • Sci-fi story about a boy living in a city that no one ever leaves, with robots and a master computer
  • Is elision applicable to acronyms? For instance, is it "LE xml" or "L'xml" ?
  • Can the universe be unpredictable but still have only one possible history?
  • Is it appropriate to ask for a raise?
  • Does a carbon fiber fuselage suffer wear from pressurization/depressurization?
  • What shape should the PCB edge have for this USB connector?
  • What does Tarski mean when he says "variables do not posses any meaning by themselves"?
  • What are ways to better show depth along a 3D curve?
  • what does "zigs when others zag" mean?
  • Why the need to recreate the whole world from scratch?
  • You're at war with countries X and Y. Does international law say anything about bombing X's embassy in Y (to kill a high-value target)?

change drive letter batch

IMAGES

  1. Quick Guide: Changing Drive Letters in Windows 10

    change drive letter batch

  2. How to Change Drive Letter in Windows 10 (Easy to Follow Guide)

    change drive letter batch

  3. How to Change Drive Letter with CMD Windows 10

    change drive letter batch

  4. [Solved] How to Change Drive Letter on Windows 11

    change drive letter batch

  5. How to Change a Drive Letter on Windows 11 & 10

    change drive letter batch

  6. How to change the drive letter in Windows 10/11, DVD and USB drives?

    change drive letter batch

VIDEO

  1. How to Change Drive Letter in Windows 11/10

  2. How to Change Drive Letter of HDD and SSD

  3. Change Drive Letter and Paths and Rename USB Drive 10/11

  4. Flash Drive Showing No Media 0 Bytes Fix In Windows 11 / 10

  5. Change Drive Letter Easily

  6. CHANGE DRIVE LETTER

COMMENTS

  1. windows

    If you run the .BAT file from the USB drive you don't need to specify the drive letter, only the path and/or file relative to the .BAT file. Example: If Unzip.BAT is in the root of the USB Drive and the .zip is in a folder called "classified docs" under a folder called "secret" it would be \secret\classified docs\

  2. How to change directory to run .bat files from different drive?

    I have some .bat files that I run from the local directory (e.g. C:\Users\pozna001). However, when I try and change the directory to a data drive using cd F:\nrcs_project to run the .bat files from a different location, I see that the command prompt does not recognize the cd command. How can I change the directory in the command prompt so that I can run these .bat files from a different drive ...

  3. batch file

    In case of the batch file is stored on the USB drive and executed from there with a double click, use xcopy "\directory" "c:\directory" /s /y because a path starting with a backslash is relative to root of current drive or use xcopy "%~d0\directory" "c:\directory" /s /y because %~d0 references the drive (letter plus colon) of first argument ...

  4. Batch file help with changing drive letter

    Hello all, I'm writing a batch file that will deploy a gold image to machines from a flash drive. I want the script to set a default letter(T) for the flash drive(so that no matter the machine type the drive letter will work), then change to the letter and run the rest of the script, but once I get out of diskpart, the script terminates and fails to both change to the new drive and continue ...

  5. Bat file changing the Drive letter depending on the PC

    Hallo, I'm running into a small issue, I am making a script to join a different domain, but I can't get my head around how to map the drives am planning on using a bat file for this. I just need a replacement for the D so it can be switch between PC's so that the drive letter changes depending on the pc. My current bat file. (this is still something I'm working on its just the start ...

  6. Running .BAT files from CMD when drive letter changes

    Then you would make a batch file with something like the second command I posted. Then copy this batch file to the root of your bootable USB stick (or whatever path you land on when you USB stick boots). Then run the batch and it will find your drive and execute the command. IF EXIST C:\diskpart1000.bat diskpart1000.bat.

  7. CD Change Directory

    Change the Current Drive, Enter the drive letter followed by a colon: C:> E: E:>. To change drive and directory at the same time: C:> cd /D E:\utils E:\utils\>. If Command Extensions are enabled, which they are by default, the CD command is enhanced as follows: The current directory string is not CASE sensitive.

  8. Change and Assign Drive Letter in Windows 10

    1 Open an elevated PowerShell. 2 Type Get-Partition into the elevated PowerShell, and press Enter. (see screenshot below) 3 Make note of the drive letter (ex: "G") of the drive you want to change. 4 Type the command below into the elevated PowerShell, and press Enter.

  9. Change a drive letter

    The following steps show how to change the drive letter. Open Disk Management with administrator permissions. In Disk Management, select and hold (or right-click) the volume on which you want to change or add a drive letter and select Change Drive Letter and Paths. Tip. If you don't see the Change Drive Letter and Paths option or it's grayed ...

  10. Change Drive Letter

    Description This script will check for a drive on a drive letter and if it finds a drive there it will move it the a new drive letter. This is great when you clone a computer that has a USB multi card reader which takes the top few drive letters and you have home drives mapped to one of those drive letters. Source Code @echo off cls title "Changing device drive letters..." set ChangeNeeded ...

  11. How to assign permanent letters to drives on Windows 10

    Search for Create and format hard disk partitions and click the top result to open the Disk Management experience. Right-click the drive and select the Change Drive Letter and Paths option. Click ...

  12. How to Change a Drive Letter on Windows 10 or Windows 11

    Changing a drive letter is pretty simple. Click the Start button, type "Disk Management" in the search bar, and then hit Enter. The program name displayed in the search will not be Disk Management. It will be "Create and format hard disk partitions." You could also hit Windows+X or right-click the Start button, and then click "Disk Management."

  13. batch file

    If anyone is lucky enough to be using Vista (Vista Ultimate SP2 b6002, in my case) and the gwmi and wmic snippets given here don't work exactly, here is what I did to make it work.. For gwmi, if you receive no output, try changing the DriveType to 3.If still having problems, remove the -filter option altogether and analyze output. gwmi win32_LogicalDisk -filter DriveType=3

  14. batch

    There you can change the drive letter that's assigned to the drive. After this is done, whenever the drive is plugged back in, ... Create your batch file scripts using %~d0 as the drive letter and colon. %~d0 is replaced by the drive containing the script. So if on one machine the thumb drive is F %~d0 is equivalent to F: On another machine the ...

  15. How do I get the drive letter a batch script is running from?

    Get the drive letter from the current directory with: %cd:~0,2% %~dp0 is pretty useful in a bat: it is the folder in which the executing bat file resides. Perhaps at the top of your script, do something like: set _SCRIPT_DRIVE=%~d0 set _SCRIPT_PATH=%~p0