1

I am new to python and wanted to make a simple script that acted like the ls command in a mac/linux terminal but for cmd in windows. The code itself works and if I run the script using python ls_script.py in my cmd it works fine. However, I want to make it so that I can run it in any active directory by just typing in ls in my cmd. I made an environment variable in cmd called ls that has a value of python ....\ls_script.py, which assumed would work since if i were to type that exact thing in manually, it works. However, when I just type in ls, it gives the following error:

"'ls' is not recognized as an internal or external command, operable program, or batch file."

asdf
  • 2,927
  • 2
  • 21
  • 42
R Nar
  • 5,465
  • 1
  • 16
  • 32
  • https://msdn.microsoft.com/en-us/library/windows/desktop/ms682057(v=vs.85).aspx or http://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt ... or make a ls.bat or ls.cmd file and put it somewhere on the path ... – Joran Beasley Sep 10 '15 at 22:57
  • yeah i dont think this helps much because python runs the script if i just input the whole thing, i want it instead to run when i just type ls – R Nar Sep 10 '15 at 23:10
  • if you made it an environmental variable named ls then you type `%ls%` I would do `doskey ls=python C:\scripts\my_script.py` and use aliases (as in the link i gave you ...(2nd one)) – Joran Beasley Sep 10 '15 at 23:13

1 Answers1

2

I don't think your problem has anything to do with python, considering that the python script does what you want. The problem is getting the environment variable to work, right?

I believe this question has the answer you're looking for:

How to create ls in windows command prompt?

In short, it looks to me like the way to achieve what you wanted was to not use environment variables, but to create a batch file instead.

Community
  • 1
  • 1
mrcheshire
  • 525
  • 2
  • 8
  • yeah i knew about this but i'm learning python rn so i wanted to know if theres any way to do it with a python script? – R Nar Sep 10 '15 at 23:08
  • 1
    You can still use your python script! The idea is you can make your ls batch file containing `python ....\ls_script.py` and then when you call ls, it will run that command, which is what you want, right? – mrcheshire Sep 10 '15 at 23:20