您可以使用 Python 的 os 和 shutil 模块来实现自动寻找并上传文件到服务器。以下是一个示例代码:\n\npython\nimport os\nimport shutil\n\n# 遍历目录,寻找后缀为 txt 和 zip 的文件\ndef find_files(directory):\n file_list = []\n for root, dirs, files in os.walk(directory):\n for file in files:\n if file.endswith(".txt") or file.endswith(".zip"):\n file_list.append(os.path.join(root, file))\n return file_list\n\n# 上传文件到服务器\ndef upload_file(file_path, server_path):\n shutil.copy(file_path, server_path)\n\n# 主程序\nif __name__ == "__main__":\n directory = "/path/to/directory" # 替换为要搜索的目录\n server_path = "/path/to/server" # 替换为服务器的路径\n\n file_list = find_files(directory)\n for file in file_list:\n upload_file(file, server_path)\n\n\n请注意,您需要将 /path/to/directory 替换为要搜索的目录的实际路径,将 /path/to/server 替换为服务器的实际路径。此外,您可能还需要根据您的服务器设置进行相应的文件上传操作。

Python 自动寻找并上传 txt 和 zip 文件到服务器

原文地址: https://www.cveoy.top/t/topic/qCZb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录