鱼C论坛

 找回密码
 立即注册
查看: 1141|回复: 6

[已解决]为什么运行一直报错 ?

[复制链接]
发表于 2018-6-12 23:43:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import os

  2. def search_file(start_dir, target):
  3.     os.chdir(start_dir)

  4.     for each_file in os.listdir(os.curdir):
  5.         if each_file == target:
  6.             print(os.getcwd() + os.sep + each_file)
  7.         if os.path.isdir(each_file):
  8.             search_file(each_file, target)
  9.             os.chdir(os.pardir)

  10. start_dir = input('请输入待查找的初始目录:')
  11. target = input('请输入需要查找的目标文件')
  12. search_file(start_dir, target)
复制代码




============================= RESTART: D:/df.py =============================
请输入待查找的初始目录:D://
请输入需要查找的目标文件Log.txt
Traceback (most recent call last):
  File "D:/df.py", line 15, in <module>
    search_file(start_dir, target)
  File "D:/df.py", line 10, in search_file
    search_file(each_file, target)
  File "D:/df.py", line 10, in search_file
    search_file(each_file, target)
  File "D:/df.py", line 4, in search_file
    os.chdir(start_dir)
PermissionError: [WinError 5] 拒绝访问。: 'S-1-5-21-822542413-1397313679-1623427173-500'
>>>
==================== RESTART: C:/Users/user/Desktop/df.py ====================
请输入待查找的初始目录:D://
请输入需要查找的目标文件Log.txt
Traceback (most recent call last):
  File "C:/Users/user/Desktop/df.py", line 15, in <module>
    search_file(start_dir, target)
  File "C:/Users/user/Desktop/df.py", line 10, in search_file
    search_file(each_file, target)
  File "C:/Users/user/Desktop/df.py", line 10, in search_file
    search_file(each_file, target)
  File "C:/Users/user/Desktop/df.py", line 4, in search_file
    os.chdir(start_dir)
PermissionError: [WinError 5] 拒绝访问。: 'S-1-5-21-822542413-1397313679-1623427173-500'
>>>
==================== RESTART: C:/Users/user/Desktop/df.py ====================
请输入待查找的初始目录:C://
请输入需要查找的目标文件Log.txt
Traceback (most recent call last):
  File "C:/Users/user/Desktop/df.py", line 15, in <module>
    search_file(start_dir, target)
  File "C:/Users/user/Desktop/df.py", line 10, in search_file
    search_file(each_file, target)
  File "C:/Users/user/Desktop/df.py", line 10, in search_file
    search_file(each_file, target)
  File "C:/Users/user/Desktop/df.py", line 4, in search_file
    os.chdir(start_dir)
PermissionError: [WinError 5] 拒绝访问。: 'S-1-5-18'
>>>
最佳答案
2018-6-13 00:01:19
PermissionError: [WinError 5] 拒绝访问


有拒绝访问的文件夹或文件
你用try 跳过就是了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-13 00:01:19 | 显示全部楼层    本楼为最佳答案   
PermissionError: [WinError 5] 拒绝访问


有拒绝访问的文件夹或文件
你用try 跳过就是了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-6-13 04:04:10 | 显示全部楼层
一些系统的隐藏文件没有权限访问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-13 18:14:29 | 显示全部楼层
ba21 发表于 2018-6-13 00:01
PermissionError: [WinError 5] 拒绝访问

我换个路径 测试 看看
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-13 18:15:08 | 显示全部楼层
小甲鱼 发表于 2018-6-13 04:04
一些系统的隐藏文件没有权限访问。

好的 我再看下 谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-13 18:19:16 | 显示全部楼层
自己新建一个路径 ,测试成功。
QQ截图20180613181809.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 22:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表