0

I’ve created a bat file to provide file path as input to my code where the path is already stored in the .bat file. My code for bat file is:

echo C:\Users\name\Files | C:\Python\Python310\python.exe “ C:\Users\name\Project\main.py”
pause

My python file has:

input_path = input()
print(input_path)
filenames = glob.glob(os.path.join(input_path, “*.xlsx”))
print(filenames)

The following code works fine till printing of input path but print(filenames) prints nothing.

My folder Files has only.xlsx files.

Edit: This was working fine when I was entering the path as input from cmd using argparse but when it reads input from bat file it is not working as it is supposed to.

  • Does this answer your question? [getting file list using glob in python](https://stackoverflow.com/questions/33747968/getting-file-list-using-glob-in-python) – tevemadar Feb 24 '22 at 16:49
  • Try glob.glob(mydir + "\*.csv") – Kasim Sharif Feb 24 '22 at 16:52
  • Both your `.bat` file and your `python` file appear to have `smart quotes`, not standard quotes. Try using a text editor, not a word processor. – Magoo Feb 24 '22 at 16:56
  • Is it sure that the Excel files are in that folder? `Files` directly in the user profile sounds suspicious, aren't they in `C:\Users\name\Documents\Files` perhaps? – tevemadar Feb 24 '22 at 16:56
  • @tevemadar yes all files are in this path only. – shikhar dhawan Feb 24 '22 at 17:00
  • @Magoo can you explain a bit more. Also I’m using a text editor. – shikhar dhawan Feb 24 '22 at 17:06
  • Please observe the quotes in your post. They are "smart quotes" - we used to call them "66 and 99" back in the stone age. Batch, at least, requires straight quotes. You need to save the file as `ANSI`, not `unicode`. Which text editor are you using? – Magoo Feb 24 '22 at 17:36
  • 1
    Ah, yes, I ran into this in a similar context, now I remember. So Windows `cmd.exe` passes everything between `echo ` and `|`, thus your path ends up as `C:\Users\name\Documents\Files `. As spaces are legal in names, `Files` and `Files ` are different folders, and you have the one without a space. `print("*"+input_path+"*")` would show it. – tevemadar Feb 27 '22 at 13:50

0 Answers0