-1
import numpy as np
import os
import matplotlib.pyplot as plt

# Loading Data
Srcpath ='/mnt/SrcFolder'
Destpath='/mnt/DestFolder'

traces= os.listdir(path)
with open(File_Sensitive_Value, 'wb') as fp:
  for trace in traces:

    Plaintext = Extract_Plaintext(trace)
    print(Plaintext)
    Ciphertext= Extract_Ciphertext(trace)
    Key= Extract_Key(trace)  
    print(Key)
    filepath = os.path.join(path, trace)
    dataArray= np.load(filepath)
    // sbox is function that have used to have the correct Sensitive value. 
    Sensitive_Value = (sbox[int(Plaintext[0:2],16) ^ int(Key[0:2],16)])
    print ("Plaintext=", int(Plaintext[0:2],16))
    print("Key=", int(Key[0:2],16))
    print ("Sensitive_Value=", Sensitive_Value)

    os.rename(os.path.join(path,trace), os.path.join(path_Sensitive_Value, trace[:-4]+'_'+'SenVal='+str('{:03}'.format(Sensitive_Value))+'.npy'))

After finding the new name of each file in my Src folder, I need to copy each file with its new name in the destfolder, od course with giving the original name of each file in the Src Folder. My solution, code lets me to delecte all the original files. How to resole this problem pleasee?

  • Have you checked [`shutil.copyfile(source, destination)`](https://docs.python.org/2/library/shutil.html#shutil.copyfile) and [`shutil.copy(source, destination_name_of_directory)`](https://docs.python.org/2/library/shutil.html#shutil.copy)? – tiwo May 12 '17 at 10:25
  • 2
    Possible duplicate of [How to move a file in Python](http://stackoverflow.com/questions/8858008/how-to-move-a-file-in-python) – polkovnikov.ph May 12 '17 at 10:31
  • @tiwo I try it now, thank you it works. –  May 12 '17 at 10:34

1 Answers1

0

This is the structure I use when I need to COPY files en bulk:

import os
import shutil

shutil.copy("OriginalFileAddress", "NewFileAddress")
print("Files moved!")

If you need to copy the metadata for the files, then use

shutil.copy2(src, dst)

instead of .copy as above.

If you need to iterate over what needs to be moved, post below and I can add new code. I hope this helps.

MJM
  • 308
  • 3
  • 9
  • Here's another really nice solution: https://stackoverflow.com/questions/45136427/python-moving-files-based-on-extensions – MJM May 08 '20 at 13:02