-1

Is there any way to create a command on Command Prompt like I want to create a command named createdirectory(I know there is an existing command for that but take this as an example) . when i execute the command "createdirectory" it will run a python file. I want it in such a way that i can run this command from anywhere any disk volume or any folder.

If you know anything then please post your answer.

Thanks!

Pritam
  • 16
  • 4
  • Open a Windows [command prompt](https://www.howtogeek.com/235101/) window, run `help` and look on the incomplete list of [Windows commands](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands) with brief description. There is also [SS64.com - A-Z index of Windows CMD commands](https://ss64.com/nt/). There can be used a macro defined with __DOSKEY__ with usage help output on running `doskey /?` or a batch file called with one or more argument strings. The help output on running `call /?` explains how to reference the arguments. – Mofi Jun 03 '22 at 18:48
  • Please take a look on [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/a/41461002/3074564) The usage of one or more batch files require to have the batch files in a directory of which path is added to __system__ or __user__ `Path` whereby the latter is most likely better in this case. Example: `@python.exe "C:\Full Path To\PythonScript.py" %*` whereby `python.exe` could be also specified with full path enclosed in `"` for most efficient (=fastest) execution. – Mofi Jun 03 '22 at 18:52

1 Answers1

1

Shell commands are basically either aliases or programs stored on disk. You can write your programs put them in some directory and add that directory path to the shell's PATH variable.

Let's say you have a program called create.py which creates the directories. You can follow these two ways to make them available as command on a shell

Assume create.py is present in /home/bob/scripts directory

Create a wrapper script

  1. Create a file called createDirectory with below content in /home/bob/scripts

    python /home/bob/scripts/create.py $*
    
  2. Add /home/bob/scripts to the PATH

    export PATH="$PATH:/home/bob/scripts"
    

Using aliases

  1. Run the alias command
    alias createDirectory="python /home/bob/scripts/create.py"
    

Usage

createDirectory <whatever> <arguments> <your> <program> <expects>

NOTE: You can add this alias command and export command to ~/.bashrc file so that it is run when you start a shell

Madhusoodan P
  • 681
  • 9
  • 20
  • 1
    Pritam was not very clear for which operating system the non-programming help is needed. But the usage of the tag [cmd](https://stackoverflow.com/tags/cmd/info) is an indication for me that a __Windows__ *Command Prompt* solution is wanted and __not__ a Linux/Max __shell__ interpreter solution. – Mofi Jun 03 '22 at 18:44
  • Yes I want it in command promt which is in windows – Pritam Jun 04 '22 at 14:20