triotype.blogg.se

Untar to folder
Untar to folder












untar to folder

Print("If directory has write permissions denied then proceed to opening text file")įound=False#Set found (duplicate indicator) to false prior to loop If(os.stat(Path_to_example_tarfile_parent_list).st_mode = 16749): #If a directory has write permissions are denied #os.remove(directory_path+'/'+name+'/example.tar')Įlif(os.stat(directory_path+'/'+each_folder_name+'/example.tar').st_mode = 33060): #Else if: no write permissions, break #tarfile.extractfile(directory_path+'/'+each_folder_name+'/') #extract tar file contents to folder #tarfile.extract(directory_path+'/'+each_folder_name+'/') T = tarfile.open(directory_path+'/'+each_folder_name+'/') Print(directory_path+'/'+each_folder_name+'/') If(os.stat(directory_path+'/'+each_folder_name+'/example.tar').st_mode = 33206):#Permissions for tar/archive file IsFile = os.path.isfile(directory_path+'/'+each_folder_name+'/example.tar')#Check if file exists in path RXList.append((directory_path+'/'+each_folder_name).replace("\\","/")) #Append new list of folders to traverse, replace double slashes with single

untar to folder

Print ("Just before checking for example_Logs") Print("Checking file permissions RW = ok")įor directory_path, subdirectories, files in os.walk(Path_to_example_tarfile_parent_list): If(os.stat(Path_to_example_tarfile_parent_list).st_mode = 16895): #If a directory/folder has write permissions Print (Path_to_example_tarfile_parent_list)įor i in range(len(Path_to_example_tarfile_parent_list)): #Create a list of directories to traverse in current year and month: If re.search('example_Logs', each_folder_name) :#Traverse directories specific directories that have example_Logs folder Path_to_example_tarfile_parent_list.append(path+each_folder_name) #Add path+folder_name to end of each folder path Path_to_example_tarfile_parent_list = #Defines list for example specific foldersįor directory_path, subdirectories, files in os.walk(path): Path = r'C:/Users/UserName/Documents/TestFolder/Folder/' When untar is complete, remove tar file and leave tar file contents in folderĬurrently the only way I could think of finding out whether the file/folder is locked is through hardcode values.With the files that are not locked (read/write denied) and contain the specific file I am looking for (example file.tar), untar the file and leave contents in the original folder.txt file as a form of logging and do not allow duplicate references of locked files Test the folder and desired tar file to see if it has specific read/writing privileges blocked, if so generate a.Traverse a directory and look in folders that are of the current year and month (YYMM*) "where * is don't care" and contain a specific file (example file.tar).

untar to folder

#Untar to folder code#

I am trying to reduce the following code and possibly create one function that can be reused to untar files.














Untar to folder