From b030391f58b63d76c256a4d59b28bb328fafc9cb Mon Sep 17 00:00:00 2001 From: "512song@sina.com" Date: Fri, 4 Apr 2025 20:13:20 +0800 Subject: [PATCH] 20250404 --- 文件管理.ipynb | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/文件管理.ipynb b/文件管理.ipynb index ef27e35..48936d0 100644 --- a/文件管理.ipynb +++ b/文件管理.ipynb @@ -64,6 +64,46 @@ "#print(dict1)" ] }, + { + "cell_type": "markdown", + "id": "bb7b6152-0fad-4917-912a-379ed49c06f9", + "metadata": {}, + "source": [ + "## 批量修改文件名" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d8abca28-6e1f-4f0a-a715-c1697cdf3f6a", + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-04T12:09:07.760344Z", + "iopub.status.busy": "2025-04-04T12:09:07.759806Z", + "iopub.status.idle": "2025-04-04T12:09:08.370898Z", + "shell.execute_reply": "2025-04-04T12:09:08.369913Z", + "shell.execute_reply.started": "2025-04-04T12:09:07.760298Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "import os,sys,shutil\n", + "import json\n", + "import glob\n", + "from pathlib import Path\n", + "\n", + "filepath = 'file/line/'\n", + "new = 'file/Line1/'\n", + "files = glob.glob(f'{filepath}*.SAC')\n", + "for fn in files:\n", + " fi_name =Path(fn).stem.split('_')[0]\n", + " n_name = Path(new,fi_name+'.SAC')\n", + " shutil.copyfile(fn,n_name)\n", + " \n", + " " + ] + }, { "cell_type": "code", "execution_count": null, @@ -1330,7 +1370,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -1344,7 +1384,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.3" + "version": "3.8.10" } }, "nbformat": 4,