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."

3
  • msdn.microsoft.com/en-us/library/windows/desktop/… or stackoverflow.com/questions/20530996/… ... or make a ls.bat or ls.cmd file and put it somewhere on the path ... Commented Sep 10, 2015 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 Commented Sep 10, 2015 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)) Commented Sep 10, 2015 at 23:13

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.