0
解决:添加os.chdir(myArg)解决了这个问题。错误 - Python的
试图运行在比我的主目录或文件/我自己direcs任何其他下面的代码时,我得到一个错误。
FileNotFoundError:[错误2]没有这样的文件或目录:
我创建在根文件和更改文件到pi所有权:PI(用户运行脚本)。如果我直接指定该文件,它的工作原理,但是,如果我运行“/”的剧本,也不会读取或任何其他文件/直销。我还创建了一个目录/ tempdir_delete /和所有权变更到PI:PI ..如果我运行该脚本专门就“/ tempdir_delete/*”,它的工作原理,但如果我离开关*失败。
它为什么失败的所有除/家庭/ PI /或我明确指定和自己的文件?它的运行统计作为用户PI,这是由须藤授予进行统计。另外,为什么我必须明确指定我自己拥有的文件?难道它不应该在root和work中看到这个文件,因为我拥有它吗?
import os
import re
import sys
import pwd
myReg = re.compile(r'^\.')
myUID = os.getuid()
myArg = sys.argv[1]
print(os.getuid())
print(pwd.getpwuid(int(myUID)))
print(myArg)
def getsize(direct):
if os.path.isfile(direct) == True:
statinfo = os.stat(myArg)
print(str(statinfo.st_size))
else:
for i in os.listdir(direct):
try:
statinfo = os.stat(i)
if myReg.search(i):
continue
else:
print(i + ' Size: ' + str(statinfo.st_size))
except:
print('Exception occurred, can't read.')
continue
getsize(myArg)