![]() ![]() # month (YYMM*) "where * is don't care" and contain a specific file (example file.tar)įind -type f -iname "$ Traverse a directory and look in folders that are of the current year and I've tested this script on my end and it works well. I've marked up the script using your requirements as comments. No_write_ek(0,0) #Set cursor to beginning of file to allow line-by-line printing With open(path+'tmp/No_Write_Permission_To_example_Folder'+curr+'txt', 'a') as no_write_file: If re.search(Path_to_example_tarfile_parent_list, line): #If current folder matches current line in txt fileįound=True #Set found (duplicate) to True, matching line found in txt file With open(path+'tmp/No_Write_Permission_To_example_Folder'+curr+'txt', 'r') as Readfile:įor line in Readfile:#For each line in txt file IsFile = os.path.isfile(path+'tmp/No_Write_Permission_To_SIL_Folder'+curr+'txt')į=open(path+'tmp/No_Write_Permission_To_Folder'+curr+'txt','w+') #Check to see if No_Write_Permission_Folder exists to store files with denied permissions 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 Print (os.path.abspath(each_folder_name)) 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/' ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |