简介:我有15个Nirsoft.com免费实用程序,我下载到Windows文件夹("源文件夹"),以及Nirsoft网页的PDF副本我下载了该实用程序。我下面的python脚本旨在为源文件夹中的每个Nirsoft实用程序的源文件夹中创建一个子目录。然后该脚本应该移动到每个新子目录,属于该子目录的压缩实用程序,以及我从中下载该实用程序的Nirsoft网页的PDF副本。
我的脚本很好地复制了压缩的实用程序。但是,我下载该实用程序的Nirsoft网页的PDF副本无法正确复制。所有子目录中的PDF副本都是损坏的,并且神秘地每个PDF副本与该子目录中的压缩实用程序具有相同的字节数。
详细说明:对于每个实用程序,我都下载到源文件夹中: 1. Nirsoft实用程序,和 2.关于该实用程序的Nirsoft页面的PDF副本。
在我的剧本中," utils_all_ls"是一个列表列表。 " utils_all_ls"中的每个列表(" util_ls")是一个包含以下内容的列表:
下面的python脚本会创建每个util_ls [0]中命名的子目录。 我的脚本确实成功地将每个子目录复制到util_ls [4]的一个很好的副本,这是压缩的Nirsoft实用程序。但是关于该实用程序的Nirsoft页面的PDF副本总是损坏的,并且PDF文件总是与该子目录中的压缩实用程序具有相同的字节数。
我无法弄清楚PDF文件(1)总是与压缩实用程序具有相同的字节数,以及(2)是否已损坏。
这是我的剧本:
import os
import sys
import re
import shutil
import zipfile
utils_all_ls = [["Process Viewer", "Process Viewer for Windows", "CurrProcess_ Freeware Process Viewer for Windows.pdf", "cprocess.zip"], ["DiskCountersView", "Hard disk info, including health", "DiskCountersView.pdf", "diskcountersview.zip"], ["DiskSmartView", "Retrieves disk health info, etc.", "DiskSmartView.pdf", "disksmartview.zip"], ["Windows Drivers Loaded", "Windows Drivers Loaded info", "DriverView_ Loaded Windows Drivers List.pdf", "driverview-x64.zip"], ["FolderChangesView", "Folder & File Changes Viewer", "FolderChangesView - Monitor folder_drive_files changes on Windows.pdf", "folderchangesview.zip"], ["JumpListsView", "Jump lists info viewer", "JumpListsView - View jump lists information stored by Windows 7.pdf", "jumplistsview.zip"], ["LastActivityView", "User actions and events Log", "LastActivityView - View the latest computer activity in Windows operating system.pdf", "lastactivityview.zip"], ["MyUninstaller", "Uninstaller - Nirsoft's", "MyUninstaller_ Alternative uninstaller to the standard Windows Add _ Remove module.pdf", "MyUninstaller___myuninst.zip"], ["ServiWin", "Windows Services & Drivers", "ServiWin_ Windows Services_Drivers Tool (start_stop_restart service).pdf", "serviwin_setup.zip"], ["ShellExView", "Explorer Context-menu fixer", "ShellExView - Shell Extension Manager For Windows.pdf", "shexview-x64.zip"], ["ShellMenuView", "Explorer Context-menu en/disable", "ShellMenuView - Disable_enable context menu items of Explorer.pdf", "shmnview-x64.zip"], ["SpecialFoldersView", "List of all special folders hyperlinked", "SpecialFoldersView - Special Folders Viewer.pdf", "specialfoldersview-x64.zip"], ["USBDeview", "USB devices installed or connected", "USBDeview View any installed_connected USB device on your system.pdf", "usbdeview-x64.zip"], ["WhatInStartup", "Startup - MsConfig alternative", "WhatInStartup - Disable_delete programs at Windows startup.pdf", "whatinstartup-x64.zip"], ["whatishang", "Hangup or program freeze info", "whatishang-x64 Get information about Windows software that stopped responding_freezing (hang).pdf", "whatishang-x64.zip"], ["wincrashreport", "Crashed Windows app reports", "WinCrashReport - Displays a report about crashed Windows application.pdf", "wincrashreport-x64.zip"], ["winprefetchview", "Prefetch file info ", "winprefetchview-x64 View the content of Windows Prefetch (.pdf", "winprefetchview-x64.zip"]]
print('\r\nLine 12: print(str(len(utils_all_ls))) = ' + str(len(utils_all_ls)) + '\r\n')
def file_accessible(filepath, mode='r'): # Check if True = File is readable
''' Check if a file exists and is accessible. '''
try:
f = open(filepath, mode)
f.close()
except IOError as e:
return False
return True
for util_no in range(0, len(utils_all_ls)):
#print('\r\nutil_no = ' + str(util_no) + '\r\n')
old_dir = r"C:\Apps\Nirsoft\Process_Related_Utils"
util_ls = utils_all_ls[util_no]
nu_dir = os.path.join(old_dir, util_ls[0])
print(nu_dir)
if 1:
for i in range(2,4):
old_file = os.path.join(old_dir, util_ls[i])
if os.path.isfile(old_file):
pass
else:
sys.exit('\r\nLine 53: Error! Error! File problem accessing file: "' + str(util_ls[i]) +'\r\n')
# Check for read access to foo.txt
if os.access(old_file, os.R_OK): # True = This means the file exists AND you can read it.
pass
else:
sys.exit('\r\nLine 53: Error! Error! File problem accessing file: "' + str(util_ls[i]) +'\r\n')
if os.access(old_file, os.W_OK): # Check for write access to the file, True = you can write to the file. If You cannot write to the file. It may or may not exist.
pass
else:
sys.exit('\r\nLine 53: Error! Error! File problem accessing file: "' + str(util_ls[i]) +'\r\n')
# if file_accessible(old_file): # check to see if file is readable
# pass
# else:
# sys.exit('\r\nLine 53: Error! Error! File problem accessing file: "' + str(util_ls[i]) +'\r\n')
os.mkdir(nu_dir)
for i in range(2,4):
if os.path.exists(nu_dir):
nu_file = os.path.join(nu_dir, util_ls[i])
shutil.copy(old_file, nu_file)
# extract the zipfiles into the newly created subdirectory
if 'zip' in str(nu_file):
zip_ref = zipfile.ZipFile(nu_file, 'r') #(path_to_zip_file, 'r') # http://stackoverflow.com/questions/3451111/unzipping-files-in-python
#print('\r\nLine 65: "nu_dir" = ' + str(nu_dir) + '\r\n')
zip_ref.extractall(nu_dir) #(directory_to_extract_to)
zip_ref.close()
""" Next, I'll create a python script with a button menu giving access to each of the .exe files and the PDF files. """