Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add delete_dirs function #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,25 @@ def split_indices(x, train=0.9, test=0.1, validate=0.0, shuffle=True): # split
return v[:i], v[i:j], v[j:k] # return indices


def delete_dirs(str_dir):
# Delete files in folders
ls = os.listdir(str_dir)
for name in ls:
c_path = os.path.join(str_dir, name)
if os.path.isdir(c_path):
delete_dirs(c_path)
else:
if c_path.endswith(".jpg") or c_path.endswith(".bmp") or c_path.endswith(".jpeg") or\
c_path.endswith(".png") or c_path.endswith(".tif") or c_path.endswith(".tiff") or\
c_path.endswith(".dng") or c_path.endswith(".txt"):
os.remove(c_path)


def make_dirs(dir='new_dir/'):
# Create folders
dir = Path(dir)
if dir.exists():
shutil.rmtree(dir) # delete dir
delete_dirs(dir) # delete dir
for p in dir, dir / 'labels', dir / 'images':
p.mkdir(parents=True, exist_ok=True) # make dir
return dir
Expand Down