有时候需要获取某目录下的所有文件和子目录,从stackoverflow搜到了一段代码,需要时可以使用。
#!/usr/bin/python import os, sys # Open a file path = "/var/www/html/" dirs = os.listdir(path) # This would print all the files and directories for file in dirs: print file
Think before you speak, read before you think.
有时候需要获取某目录下的所有文件和子目录,从stackoverflow搜到了一段代码,需要时可以使用。
#!/usr/bin/python import os, sys # Open a file path = "/var/www/html/" dirs = os.listdir(path) # This would print all the files and directories for file in dirs: print file
Leave a Reply