-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathData.py
35 lines (24 loc) · 810 Bytes
/
Data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
from pathlib import Path
import shutil
def readFile(fileName):
idFile = open(fileName, "r") # opens the file in read mode
id_list = idFile.read().splitlines() # puts the file into an array
idFile.close()
return id_list
def main():
# read ids.txt as a list
idstxt_path = '' #for example :'val2017/ids.txt'
ids_list = readFile(idstxt_path)
# copy the image with id in ids_list to folder selectedData
dataset = ''
selectedData = ''
for filename in os.listdir(dataset):
#remove .jpg to see if its in ids_list
name = Path(filename).with_suffix('')
if str(name) in ids_list:
path = dataset+str(filename)
shutil.copy(path, selectedData)
else:
continue
main()