-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandFilePicker.py
More file actions
40 lines (26 loc) · 847 Bytes
/
randFilePicker.py
File metadata and controls
40 lines (26 loc) · 847 Bytes
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
36
37
38
39
40
import os
import random
class pathFlattener():
def __init__(self, path='.'):
self.path = path
self.files = self.flatten()
def flatten(self):
files = []
for f in os.walk(self.path):
files.extend([os.path.join(f[0], x) for x in f[2]])
return files
class randomFilePicker(pathFlattener):
def __init__(self, path='.'):
super().__init__(path)
def pick(self, num=1):
self.picked = random.sample(self.files, num)
def rmPicked(self):
for f in self.picked:
os.remove(f)
def hidePicked(self):
for f in self.picked:
newname = os.path.join(os.path.dirname(f), '.' + os.path.basename(f))
os.rename(f, newname)
c = randomFilePicker()
c.pick()
print(c.picked)