Skip to content
Advertisement

Expanding asterisk in glob

I want to be able to print a list of all file in a directory in linux but my code only print out the first item in the directory

inside home directory is text1.txt, text2.txt, text3.txt

sys.argv[1] should be /home/* when I run it on command line:

JavaScript

Script:

JavaScript

the output is only the first file in the directory

JavaScript

any idea? The code works fine on Windows but when I moved it to Linux, it doesn’t work anymore

Thanks

Advertisement

Answer

Since the shell expands the wildcard, you don’t need to call glob. Just print all the arguments in sys.argv

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement