Search code examples
pythonfilecmdoperating-system

Locating and reading all .py files


when i start the programm in vs every thing is working fine, but when i start it with python over the cmd there is no output

import glob
Liste = ""
progs = glob.glob("*/*.py")
for Prog in progs:
    fh = open(Prog, "r")
    pCode = fh.readlines()
    fh.close()
    for line in pCode:
        Liste +=(line)

so when i want to print the variable: "Liste" there is (when i am starting in vs) all the codes but when i am starting in cmd its blank, please help


Solution

  • I assume you don't invoke your script from the same directory in Visual Studio than you do in the console...

    glob.glob("*/*.py") creates a list of strings containing relative paths to Python files in any sub directory of the current working directory.

    So if you invoke the script using different working directories will return different results.

    See also: