0

I'm new to Windows and I know how to do it in Unix systems. In Windows 10, suppose that I want, in my Windows Command Processor, that the command d permanently does exactly the same as cd then ls, how would I do this ?

For instance, I'm in this Command Processor, and when I type d C:Users, this is equivalent of doing cd C:Users + ls and that goes then lists all my files and directories in this folder.

EDIT thanks to @montonero : You can replace the "Windows Command Processor" by "PowerShell" and my question still remains :D

8
  • @Biswapriyo then how could I to this with environment variables? I'm open to any workaround.
    – JKHA
    Apr 26, 2019 at 14:51
  • You can use Doskey for this, but to have the macro persistent you'll have to store it/them in a file and use an autorun to have them loaded automatically.
    – LotPings
    Apr 26, 2019 at 14:52
  • @LotPings, as I'm new to Windows, these are new terms for me, could you please write your workaround and its steps as an answer to my question? Then I'll select it when I'll succeed doing it :D
    – JKHA
    Apr 26, 2019 at 15:00
  • The macro to use (non persistent) is doskey d=cd /d $*$Tdir
    – LotPings
    Apr 26, 2019 at 15:00
  • @LotPings Thank you, so this is a partial answer to my question if I correctly understood, what about the autorun part?
    – JKHA
    Apr 26, 2019 at 15:01

2 Answers 2

1

I've managed to do what I wanted thanks to @montonero suggesting me to move to PowerShell.

I used this question and its second answer by Chase Florell using this code for PowerShell script .ps1:

function ShortCut-cd ($1){
    cd $1
    ls
}

Set-Alias d ShortCut-cd
0

In Windows cmd you would save this as, say, cddir.cmd somewhere in your path:

cd %1 dir

Then run cddir \data

But I too prefer the powershell answer if you work in powershell

2
  • Thank you for your answer, I would rather name it c.cmd rather than cddir because the point of my command was saving time each time I use change directory command :)
    – JKHA
    Apr 29, 2019 at 14:15
  • 1
    You can call it anything you want!
    – uSlackr
    Apr 30, 2019 at 0:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .