python copy file based on header -


on python, need in searching files specific header type(pst file, header sequence 21 42 44 4e) , copy them saved files directory.

below relevant excerpts code.

# working directory of program ori_path=os.getcwd() # file saved(from root directory of program) temp = "\etc\saved files" # obtain value written in textbox, path search path_to_copy_from=self.textbox.getvalue() # create absolute destination path files don't end somewhere shouldn't   copy_path="{}{}".format(ori_path,temp)      # change working directory 1 specified user os.chdir(path_to_copy_from) 

i using shutil copying such:

shutil.copy(files,copy_path) 

some searches found mentioned using itertools, can't understand example (hence, why asking question). need in coming code @ file header , invoke shutil if header matches pst header format.

to obtain first 4 bytes of file in hex format question:

header = "" open(path_to_copy_from, 'rb') f:     in range(4):         byte = f.read(1)         header += hex(ord(byte))[2:] + " " 

you can check each file in folder whether header string matches 1 you're looking for.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -