# Script Name : script_listing.py# Author : Craig Richards# Created : 15th February 2012# Last Modified : 29th May 2012# Version : 1.2# Modifications : 1.1 - 28-02-2012 - CR - Added the variable to get the logs directory, I then joined the output so the file goes to the logs directory# : 1.2 - 29-05/2012 - CR - Changed the line so it doesn't ask for a directory, it now uses the environment varaible scripts# Description : This will list all the files in the given directory, it will also go through all the subdirectories as wellimport os # Load the library modulelogdir = os.getenv("logs") # Set the variable logdir by getting the value from the OS environment variable logslogfile = 'script_list.log' # Set the variable logfilepath = os.getenv("scripts") # Set the varable path by getting the value from the OS environment variable scripts - 1.2#path = (raw_input("Enter dir: ")) # Ask the user for the directory to scanlogfilename = os.path.join(logdir, logfile) # Set the variable logfilename by joining logdir and logfile togetherlog = open(logfilename, 'w') # Set the variable log and open the logfile for writingfor dirpath, dirname, filenames in os.walk(path): # Go through the directories and the subdirectoriesfor filename in filenames: # Get all the filenameslog.write(os.path.join(dirpath, filename)+'\n') # Write the full path out to the logfileprint ("\nYour logfile " , logfilename, "has been created") # Small message informing the user the file has been created
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。