Python implementation of endnote download PDF file

Source: Internet
Author: User

Endnote downloaded files placed in a PDF folder in a heap of scrambled numbers in the folder

Now the boss asked to download the files sent to him, but a copy of the feeling some eggs hurt, so think of Python, through the data, the perfect realization of the function of this finishing, is really a python dafa good 2333333333333

Final effect:

I python rookie, write bad place, please forgive me

#--------------------"classify.py"------------------# author:zhyh2010# date:201505113# Target: Organize endnote automatically downloaded PDF files and move them to a folder#-------------------------"End"--------------------------ImportOs.pathImportShutil#-------------------------"class classify"--------------------------# Para:curpath Current Path# Extension Extension# Target_dir Destination Storage folder# Three member variables are initialized in Init, and modifying these three parameters in Init will enable the extension of the function.#-------------------------"class classify end"-------------------------- class classify:Curpath ="'Extension ="'Target_dir ="'     def __init__(self):Self.curpath = OS.GETCWD () self.extension ='. pdf 'Self.target_dir =' Endnote pdf '    #-------------------------"Classify_file"--------------------------    # target: Traverse the path of the path file and move the PDF file in the folder to the appropriate directory    #-------------------------"Classify_file End"--------------------------     def classify_file(self):Extension = self.extension Path = Self.curpathif  notOs.path.isdir (PATH):# Determine if the path isPrint' error! It is not a dir ')returnSelf.makedir () forRoot, dirs, listinchOs.walk (PATH): forFileinchListifFile.endswith (extension): Print (' moving\t '+ file +' The \ting ... ' .... ')Try: Self.movefiles (Os.path.join (root, file))except:ContinuePrint'-------------------done-----------------')#-------------------------"MakeDir"--------------------------    # Target: Create destination folder    #-------------------------"MakeDir End"---------------------     def makedir(self):Target_dir = Self.target_dirif  notOs.path.exists (Target_dir): Os.mkdir (Target_dir)#-------------------------"Movefiles"--------------------------    # target: Move files to file directory    #-------------------------"Movefiles End"---------------------     def movefiles(self, file):Target_dir = Self.target_dir shutil.copy (file, Target_dir)#instance = classify missing () does not initialize selfInstance = classify () Instance.classify_file ()

Resources
1.Python notes-Class definition

2.Python file Operations and folder traversal

StartsWith and EndsWith functions of 3.Python

4.Python Shutil Module

5python determine if files and folders exist

6try.. Except

Python implementation of endnote download PDF file

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.