dong625 commited on
Commit
984fbb2
·
verified ·
1 Parent(s): 10c17c5

Upload search_files.ipynb

Browse files
Files changed (1) hide show
  1. search_files.ipynb +60 -10
search_files.ipynb CHANGED
@@ -2,18 +2,18 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 2,
6
  "id": "e3d91216-d411-4039-a914-3d5e23cb5335",
7
  "metadata": {
8
  "ExecutionIndicator": {
9
  "show": true
10
  },
11
  "execution": {
12
- "iopub.execute_input": "2024-08-16T09:45:06.206727Z",
13
- "iopub.status.busy": "2024-08-16T09:45:06.206308Z",
14
- "iopub.status.idle": "2024-08-16T09:45:06.266958Z",
15
- "shell.execute_reply": "2024-08-16T09:45:06.266529Z",
16
- "shell.execute_reply.started": "2024-08-16T09:45:06.206705Z"
17
  },
18
  "tags": []
19
  },
@@ -22,7 +22,7 @@
22
  "name": "stdout",
23
  "output_type": "stream",
24
  "text": [
25
- "['/mnt/workspace/stable-diffusion-webui/modules/ui_postprocessing.py', '/mnt/workspace/stable-diffusion-webui/modules/.ipynb_checkpoints/ui_postprocessing-checkpoint.py']\n"
26
  ]
27
  }
28
  ],
@@ -50,12 +50,62 @@
50
  " return matching_files\n",
51
  "\n",
52
  "# 示例用法\n",
53
- "directory = '/mnt/workspace/stable-diffusion-webui'\n",
54
- "search_string = 'Batch from Directory'\n",
55
  "file_extension = '.py' # 仅搜索特定格式的文件\n",
56
  "matching_files = find_files_with_string(directory, search_string, file_extension)\n",
57
  "print(matching_files)"
58
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  }
60
  ],
61
  "metadata": {
@@ -74,7 +124,7 @@
74
  "name": "python",
75
  "nbconvert_exporter": "python",
76
  "pygments_lexer": "ipython3",
77
- "version": "3.10.12"
78
  }
79
  },
80
  "nbformat": 4,
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "id": "e3d91216-d411-4039-a914-3d5e23cb5335",
7
  "metadata": {
8
  "ExecutionIndicator": {
9
  "show": true
10
  },
11
  "execution": {
12
+ "iopub.execute_input": "2024-11-21T10:25:21.652021Z",
13
+ "iopub.status.busy": "2024-11-21T10:25:21.651701Z",
14
+ "iopub.status.idle": "2024-11-21T10:25:21.931775Z",
15
+ "shell.execute_reply": "2024-11-21T10:25:21.931295Z",
16
+ "shell.execute_reply.started": "2024-11-21T10:25:21.652000Z"
17
  },
18
  "tags": []
19
  },
 
22
  "name": "stdout",
23
  "output_type": "stream",
24
  "text": [
25
+ "['/mnt/workspace/ComfyUI/custom_nodes/ComfyUI-Custom-Scripts/py/play_sound.py']\n"
26
  ]
27
  }
28
  ],
 
50
  " return matching_files\n",
51
  "\n",
52
  "# 示例用法\n",
53
+ "directory = '/mnt/workspace'\n",
54
+ "search_string = 'notify.mp3'\n",
55
  "file_extension = '.py' # 仅搜索特定格式的文件\n",
56
  "matching_files = find_files_with_string(directory, search_string, file_extension)\n",
57
  "print(matching_files)"
58
  ]
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": 2,
63
+ "id": "995ae9bc-5282-4403-aa6d-50839485e6b0",
64
+ "metadata": {
65
+ "execution": {
66
+ "iopub.execute_input": "2024-11-21T10:30:56.497870Z",
67
+ "iopub.status.busy": "2024-11-21T10:30:56.497554Z",
68
+ "iopub.status.idle": "2024-11-21T10:30:56.505407Z",
69
+ "shell.execute_reply": "2024-11-21T10:30:56.504867Z",
70
+ "shell.execute_reply.started": "2024-11-21T10:30:56.497847Z"
71
+ },
72
+ "tags": []
73
+ },
74
+ "outputs": [
75
+ {
76
+ "name": "stdout",
77
+ "output_type": "stream",
78
+ "text": [
79
+ "找到文件: /mnt/workspace/ComfyUI/custom_nodes/ComfyUI-Custom-Scripts/web/js/assets/notify.mp3\n"
80
+ ]
81
+ }
82
+ ],
83
+ "source": [
84
+ "import os\n",
85
+ "\n",
86
+ "def find_file(target_file, search_path):\n",
87
+ " \"\"\"\n",
88
+ " 遍历目录寻找目标文件,返回文件的完整路径。\n",
89
+ " :param target_file: 要寻找的文件名\n",
90
+ " :param search_path: 搜索的起始目录路径\n",
91
+ " :return: 文件的完整路径,未找到返回 None\n",
92
+ " \"\"\"\n",
93
+ " for root, dirs, files in os.walk(search_path):\n",
94
+ " if target_file in files:\n",
95
+ " return os.path.join(root, target_file)\n",
96
+ " return None\n",
97
+ "\n",
98
+ "# 示例用法\n",
99
+ "if __name__ == \"__main__\":\n",
100
+ " search_dir = \"/mnt/workspace/ComfyUI\" # 替换为实际的目录路径\n",
101
+ " file_name = \"notify.mp3\" # 替换为你要寻找的文件名\n",
102
+ "\n",
103
+ " result = find_file(file_name, search_dir)\n",
104
+ " if result:\n",
105
+ " print(f\"找到文件: {result}\")\n",
106
+ " else:\n",
107
+ " print(\"未找到目标文件\")\n"
108
+ ]
109
  }
110
  ],
111
  "metadata": {
 
124
  "name": "python",
125
  "nbconvert_exporter": "python",
126
  "pygments_lexer": "ipython3",
127
+ "version": "3.10.13"
128
  }
129
  },
130
  "nbformat": 4,