-1

I have a text file as below.

4b64dac0d3b4592143368e6c2d676039165b6159  Detections: -1
0e00854b6b9e431ce1fe56b9bcebdb6b8f088012  Detections: 0
1c1fc6283eb75cc1fd2885a81d43843009ebba77  Detections: 14
2e19a1b2e451e799b2feaba39148cfd2740de8e2  Detections: 5
3a0761b29c55135122fcdb2ebb72519306ea4b35  Detections: 1

And Five files named as mentioned above in one location:

In that, i want to move file to specific folder based on detection Condition. The condition are: If detection is greater than Zero means, it move to folder name "found". If detection is lesser and equal to Zero means , it move to folder name "Not found".

Result would be:

In Found folder,

1c1fc6283eb75cc1fd2885a81d43843009ebba77
2e19a1b2e451e799b2feaba39148cfd2740de8e2
3a0761b29c55135122fcdb2ebb72519306ea4b35

These files will be moved

and In Not Found Folder,

4b64dac0d3b4592143368e6c2d676039165b6159
0e00854b6b9e431ce1fe56b9bcebdb6b8f088012

These files will be moved.

Can anyone could help me through done this?

i have tried like:

with open('D:\SHARE\Check\check.txt') as infile:
  for line in infile:
    if condition:
      Detections: 0
      next(infile)

I don't know how to check condition and move file based on that

pvg
  • 2,673
  • 4
  • 17
  • 31
pavithran G
  • 112
  • 2
  • 13

1 Answers1

0

You can make the condition this way:

with open('D:\SHARE\Check\check.txt','r') as checkfile:
    content = checkfile.readlines()

content = [x.strip() for x in content] # here is the content of your file without empty elements

for i in content:
    file_line = i.split(' ')
    if int(file_line[2].strip()) > 0: # if condition is greater that zero
        #move to found
    else: #if condition is zero or less
        #move to not found

And here you can find how to move the file: How to move a file in Python

Community
  • 1
  • 1
Olia
  • 815
  • 4
  • 16