Python无法创建符号链接

时间:2016-12-20 20:27:21

标签: python windows symlink

我正在尝试使用python来创建符号链接。当我尝试使用os.symlink时,我得到一个WinError 5“访问被拒绝”错误,但如果我尝试使用mklink创建相同的符号链接,它可以正常工作。 (我是以管理员身份运行它,并具有“创建符号链接”权限。)

然后我使用subprocess.call直接使用正确的参数调用mklink,并且它运行时没有任何错误,但是当它完成时,尚未创建符号链接。

当我尝试使用Popen运行命令时,即使目录存在,我也会得到'系统无法找到指定的文件'错误。

这是在Windows Server 2008上。

def createStudentFolders(studentList):
     grad_year = input("Please enter the year of graduation for the class of students being created (i.e. 2016): ")
     for student in studentList:

         student = student.replace(" ","") # Gets rid of the white space in the name
         studentPath = 'cpwd/{}'.format(student)

         try:
             os.mkdir(studentPath)
         except:
        pass



         print(studentPath)
         proc = Popen("icacls {} /inheritance:e /grant STUDENT\{}:(OI)(CI)F /T".format(studentPath, student))

         classFolder = "students/ClassOf{}".format(grad_year)

         try:
             os.mkdir(classFolder)
         except:
             pass



         os.symlink('{}/{}'.format(classFolder, student), studentPath, target_is_directory=True)


         print("Done")


def main():
   newStudentsLoc = "newStudents.txt"
   studentList = readStudentsToList(newStudentsLoc)
   createStudentFolders(studentList)

 main()
 input("Pausing")

文件位于Z:\

里面是

cpwd\<student folders>
students\ClassOf<Year>\<symlinks to student folders go here>

我尝试过使用绝对路径但没有运气。

0 个答案:

没有答案
相关问题