浏览代码

新增获取文件夹和文件路径功能

admin 1 年之前
父节点
当前提交
62598634a3

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 30 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,30 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
+    <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
+      <option name="ignoredPackages">
+        <value>
+          <list size="1">
+            <item index="0" class="java.lang.String" itemvalue="mysqlclient" />
+          </list>
+        </value>
+      </option>
+    </inspection_tool>
+    <inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
+      <option name="ignoredErrors">
+        <list>
+          <option value="N802" />
+          <option value="N801" />
+        </list>
+      </option>
+    </inspection_tool>
+    <inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
+      <option name="ignoredIdentifiers">
+        <list>
+          <option value="int.*" />
+        </list>
+      </option>
+    </inspection_tool>
+  </profile>
+</component>

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 7 - 0
.idea/misc.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
+  <component name="PyPackaging">
+    <option name="earlyReleasesAsUpgrades" value="true" />
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/pi_liang_chong_ming_min.iml" filepath="$PROJECT_DIR$/.idea/pi_liang_chong_ming_min.iml" />
+    </modules>
+  </component>
+</project>

+ 8 - 0
.idea/pi_liang_chong_ming_min.iml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>

+ 22 - 0
获取文件名.py

@@ -0,0 +1,22 @@
+import os
+"""只获取文件名称"""
+def list_files_and_folders(folder_path):
+    print(f"Files and folders in {folder_path}:")
+
+    # 列出文件夹
+    for root, dirs, files in os.walk(folder_path):
+        for dir_name in dirs:
+            print(f"[文件夹] {dir_name}")
+
+        # 列出文件
+        for file_name in files:
+            print(f"[文件] {file_name}")
+
+if __name__ == "__main__":
+    target_folder = r"/Users/admin/Downloads/2022年度领导班子总结和干部个人述职报告的副本"
+    list_files_and_folders(target_folder)
+
+#
+# # 指定文件夹路径,确保使用 Unicode 编码
+# folder_path = r"/Users/admin/Downloads/2022年度领导班子总结和干部个人述职报告的"
+#

+ 20 - 0
获取文件名及后缀名称.py

@@ -0,0 +1,20 @@
+import os
+"""加单独的路径和后缀名"""
+def list_files_and_folders(folder_path):
+    print(f"Files and folders in {folder_path}:")
+
+    # 列出文件夹
+    for root, dirs, files in os.walk(folder_path):
+        for dir_name in dirs:
+            folder_full_path = os.path.join(root, dir_name)
+            print(f"[Folder] {dir_name} - {folder_full_path}")
+
+        # 列出文件
+        for file_name in files:
+            file_full_path = os.path.join(root, file_name)
+            file_name, file_extension = os.path.splitext(file_name)
+            print(f"[File] {file_name} - {file_full_path} - Extension: {file_extension}")
+
+if __name__ == "__main__":
+    target_folder = r"/Users/admin/Downloads/2022年度领导班子总结和干部个人述职报告的副本"
+    list_files_and_folders(target_folder)