From cbc1f8e56bfbdb41e8c1fb36645851df655ee798 Mon Sep 17 00:00:00 2001 From: "512song@sina.com" Date: Fri, 6 May 2022 22:36:23 +0800 Subject: [PATCH] 20020506 --- 文件管理1.ipynb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/文件管理1.ipynb b/文件管理1.ipynb index 052b134..fd3d8dc 100755 --- a/文件管理1.ipynb +++ b/文件管理1.ipynb @@ -64,6 +64,42 @@ "#print(dict1)" ] }, + { + "cell_type": "markdown", + "id": "bbf0b425-c0ce-4608-ae52-85a78ddcd6c0", + "metadata": {}, + "source": [ + "## 批量更换扩展名" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2c2bd1d1-4d84-4639-ba20-c97c218ae275", + "metadata": { + "execution": { + "iopub.execute_input": "2022-05-06T14:01:25.901198Z", + "iopub.status.busy": "2022-05-06T14:01:25.900687Z", + "iopub.status.idle": "2022-05-06T14:01:25.911729Z", + "shell.execute_reply": "2022-05-06T14:01:25.910606Z", + "shell.execute_reply.started": "2022-05-06T14:01:25.901153Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "import glob\n", + "import os,shutil\n", + "\n", + "filepath = 'file/yimo/'\n", + "old = 'SGF'\n", + "new = 'sgf'\n", + "files = glob.glob(f'{filepath}*.{old}')\n", + "for f in files:\n", + " new_file =os.path.splitext(f)[0]+'.'+new\n", + " os.rename(f,new_file)" + ] + }, { "cell_type": "markdown", "id": "69712868-6786-430b-8591-f6828d781588",