![]() Open ( in_file ) print ( strftime ( "%H:%M:%S" ), " " s " -> pdf ", path. abspath ( folder " \\ " new_name ) doc = word. abspath ( folder " \\ " files ) new_file = path. replace ( "." s, r".pdf" ) in_file = path. endswith ( ".docx" ): s, match = "docx", 1 if match : new_name = files. endswith ( ".doc" ): s, match = "doc", 1 elif files. DispatchEx ( "Word.Application" ) for files in listdir ( getcwd ()): match = 0 if files. BYE, BYE!." ) exit () else : print ( " \n Number of doc and docx files: ", num_docx num_doc, " \n " ) print ( strftime ( "%H:%M:%S" ), "Starting to convert files. \n " ) print ( strftime ( "%H:%M:%S" ), "There are no files to convert. if num_docx num_doc = 0 : print ( " \n The specified folder does not contain docx or docs files. num_docx = count_files ( ".docx" ) num_doc = count_files ( ".doc" ) # Check if the number of docx or doc files is equal to 0 (= there are no files # to convert) and if so stop executing the script. ![]() chdir ( folder ) # Count the number of docx and doc files in the specified folder. ![]() \n " ) abs_path = input ( prompt ) return abs_path print ( " \n " ) folder = check_path ( "Provide absolute path for the folder: " ) # Change the directory. exists ( abs_path ) != True : print ( " \n The specified path does not exist. ''' abs_path = input ( prompt ) while path. def check_path ( prompt ): ''' (str) -> str Verifies if the provided absolute path does exist. The user is prompted for a path until the existence of the # provided path has been verified. endswith ( filetype ): count_files = 1 return count_files # Function "check_path" is used to check whether the path the user provided does # actually exist. > count_files(".docx") 11 ''' count_files = 0 for files in listdir ( folder ): if files. ![]() # Convert doc and docx files to pdf (Python recipe) from os import chdir, getcwd, listdir, path from time import strftime from win32com import client def count_files ( filetype ): ''' (str) -> int Returns the number of files given a specified file type. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |