Below is a script in a file named nfile on LINUX:
#! /usr/bin/env python
import os
nfile = 0
for path,dlist,flist in os.walk('.'):
nfile = len(flist)
print("Number of files: {0}".format(nfile))
It is located in a directory that is on my PATH and if I say "nfile" from anywhere it gives me a count of the number of files (Note: I never use symbolic links).
I want to replicate the same functionality on Windows 11. I have been able to gather that the Python Launcher for Windows can be used to obtain that functionality.
I use Anaconda Python which does not install the launcher. How can Anaconda users install the launcher?
Once the launcher is installed, it is not at all clear to me how to get the functionality discussed above. I can put "nfile" on my Windows PATH. Do I need to make it executable as on Linux? Do I say "py nfile" at the command line or something?
CodePudding user response:
Not sure if I understood your question correctly, but I guess you want to run the command 'nfile' from anywhere in Windows command line.
This is possible with the help of another batch (.bat) file. You need create a file called 'nfile.bat' next to the script. Both the script and batch file need to be in a location that's defined in PATH.
The content of the batch file should contain something like:
python nfile.py