Created
March 15, 2019 01:13
-
-
Save uzl/cb41bbc34771a416e8558edea2708c57 to your computer and use it in GitHub Desktop.
scanning directory and sub directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import glob" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"src_root_dir = '/home/uzzal/Documents/office_dev/out'\n", | |
"\n", | |
"label_list = glob.glob(src_root_dir + '/**/*.txt', recursive=True)\n", | |
"image_list = glob.glob(src_root_dir + '/**/*.png', recursive=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"label found: 255\tImage found: 255\n" | |
] | |
} | |
], | |
"source": [ | |
"label_path_dic = dict()\n", | |
"image_path_dic = dict()\n", | |
"\n", | |
"\n", | |
"for full_path in label_list:\n", | |
" file_name = full_path.split('/')[-1].split('.')[0]\n", | |
" label_path_dic[file_name] = full_path\n", | |
"\n", | |
"\n", | |
"for full_path in image_list:\n", | |
" file_name = full_path.split('/')[-1].split('.')[0]\n", | |
" image_path_dic[file_name] = full_path\n", | |
" \n", | |
"print('label found: {}\\tImage found: {}'.format(len(label_path_dic), len(image_path_dic)) )" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment