Skip to content

Instantly share code, notes, and snippets.

@ashnair1
Last active May 1, 2021 07:11
Show Gist options
  • Save ashnair1/1b0e97f9d54a6a10966b2ddb72fe6121 to your computer and use it in GitHub Desktop.
Save ashnair1/1b0e97f9d54a6a10966b2ddb72fe6121 to your computer and use it in GitHub Desktop.
import os
import shutil
src_dir = "./Files"
dst_dir = "./Result"
"""
Accepted format
{dialect}_{question}__{arab_pnc}_{keyword(s)}_timestamp.txt
Number of keywords range from 1 to 2
"""
def main():
files = os.listdir(src_dir)
for dia_dir in files:
for i in os.listdir(os.path.join(src_dir, dia_dir)):
name = i.split('_')
dialect = name[0]
question = name[1]
arab_pnc = name[3]
timestamp = name[-1][:-4]
#import pdb; pdb.set_trace()
if len(name) not in [6,7]:
continue
#raise AssertionError(f"Filename {i} is invalid")
if len(name) == 7:
keywords = [dialect, name[4], name[5]]
else:
keywords = [dialect, name[4]]
cls_dir_name = '_'.join(keywords)
#print(f"Creating {cls_dir_name}")
dst_name = os.path.join(dst_dir, cls_dir_name)
if not os.path.isdir(dst_name):
os.makedirs(dst_name, exist_ok=True)
#print(f"Copying {cls_dir_name}")
src_path = os.path.join(src_dir, dia_dir, i)
dst_path = os.path.join(dst_name, i)
shutil.copy(src_path, dst_path)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment