I've been trying to use a loop to create multiple aliases without success. I'm not a professional, please bear with me... Does anyone know what's wrong in my code or how I can implement this in the command prompt? I know how to do this in PowerShell but I'm trying to reproduce the code for cmd. Here's the code:


FOR %%G IN (a,b,c,d,e,f,g,h) DO (
    DOSKEY %%GG=cd %%GG:\

Here's what I get as a result when running the macro:

  • So what do you see or experience with the batch file? – Appleoddity Oct 29 '18 at 1:05
  • I've just added a screenshot. – prubini87 Oct 29 '18 at 1:12
  • note that the Windows cmd is not DOS. There's no for loop like that in DOS – phuclv Oct 29 '18 at 9:40

You're defining DOSKEY %%GG=cd %%GG:\ (with double Gs), so you must type aG in order to change into the drive aG: (which is not a valid drive letter). Same to other drives

Moreover to change the current drive you use only the drive letter instead of cd. So to change to the current directory on A: just run A:. However if you want to force changing both the current drive and current directory then use the /D option

You must remove the unnecessary G there


FOR %%G IN (a,b,c,d,e,f,g,h) DO (
    DOSKEY %%G=%%G:
    rem Or DOSKEY %%G=cd /D %%G:
  • Aww... Thank you very much! That's it! :D – prubini87 Oct 29 '18 at 7:52

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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