Python Novice Grey Hat script Practice---file path traversal collection

Source: Internet
Author: User

General idea:

Os.path.abspath ('. ') #获取当前路径

Os.listdir #获取指定的文件夹包含的文件或文件夹的名字的列表

Os.path.join #用获取的文件名拼接路径

Os.path.isdir #判断路径是否为目录, for recursion

1 #-*-coding:utf-8-*-2 3 __author__='Dou-wei'4 5 ImportOS6 ImportSYS7 8file_name = sys.argv[1]#get the user's terminal input to name the file9Start_path = Os.path.abspath ('.')#Get current pathTenHost = Os.path.join (Start_path,file_name)#Stitching Path Onef = open (host,'W')#Create a writable file in a stitched path A  - defSearch (path): -      forXinchOs.listdir (PATH):#os.listdir (path) Returns a list of the names of the files or folders that are contained in the specified folder theCurrent_name = Os.path.join (path,x)#Stitching Path -F.write (Current_name)#write to the path that contains the file name -F.write ('\ n')#line Break -         ifOs.path.isdir (Current_name):#determine if the path is a directory +Search (Current_name)#recursive execution, further exploration -  + defMain (): A     Try: at Search (Start_path) -     exceptException,e:#Output error message -         Printe -  - if __name__=='__main__': -Main ()
View Code

Approximate effect:

Python Novice Grey Hat script Practice---file path traversal collection

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.