Skip to content

Instantly share code, notes, and snippets.

@rettouseinosugakubenkyo
Created November 29, 2018 20:23
Show Gist options
  • Save rettouseinosugakubenkyo/823cbc0867c9b759511c075c1cb3c1dc to your computer and use it in GitHub Desktop.
Save rettouseinosugakubenkyo/823cbc0867c9b759511c075c1cb3c1dc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import glob\n",
"import shutil\n",
"import os\n",
"\n",
"def copy_all_csvfiles(source_dire_name, dist_dire_name):\n",
" \"\"\" フォルダ内のすべてのcsvファイルをコピーする。\n",
" \"\"\"\n",
" n = 0 # カウント用\n",
"\n",
" # コピー元フォルダ内のcsvファイルを取得\n",
" source_paths = glob.glob(os.path.join(source_dire_name, '*.csv'))\n",
"\n",
" # 全てのcsvファイルをコピー\n",
" for source_path in source_paths:\n",
" # コピー先パスを作製\n",
" source_file_name = os.path.basename(source_path)\n",
" dist_path = os.path.join(dist_dire_name, source_file_name)\n",
" # 表示\n",
" print(source_path + ' -> ' + dist_path)\n",
" # コピー\n",
" shutil.copy2(source_path, dist_path)\n",
" n += 1\n",
"\n",
" print(str(n)+\"ファイルにコピー完了\")\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"C:\\python\\temp\\1301.csv -> C:\\python\\temp2\\1301.csv\n",
"C:\\python\\temp\\1332.csv -> C:\\python\\temp2\\1332.csv\n",
"C:\\python\\temp\\1333.csv -> C:\\python\\temp2\\1333.csv\n",
"C:\\python\\temp\\1352.csv -> C:\\python\\temp2\\1352.csv\n",
"C:\\python\\temp\\1376.csv -> C:\\python\\temp2\\1376.csv\n",
"C:\\python\\temp\\1377.csv -> C:\\python\\temp2\\1377.csv\n",
"C:\\python\\temp\\1379.csv -> C:\\python\\temp2\\1379.csv\n",
"C:\\python\\temp\\1380.csv -> C:\\python\\temp2\\1380.csv\n",
"C:\\python\\temp\\1381.csv -> C:\\python\\temp2\\1381.csv\n",
"C:\\python\\temp\\1382.csv -> C:\\python\\temp2\\1382.csv\n",
"10ファイルにコピー完了\n"
]
}
],
"source": [
"source_path = r\"C:\\python\\temp\"\n",
"dist_path = r\"C:\\python\\temp2\"\n",
"\n",
"copy_all_csvfiles(source_path, dist_path)"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"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.5.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment