我正在尝试创建symlinks
在 Windows 8 上使用 Python。我发现这个帖子 https://stackoverflow.com/questions/1447575/symlinks-on-windows这是我脚本的一部分。
import os
link_dst = unicode(os.path.join(style_path, album_path))
link_src = unicode(album_path)
kdll = ctypes.windll.LoadLibrary("kernel32.dll")
kdll.CreateSymbolicLinkW(link_dst, link_src, 1)
首先,只有通过管理员cmd执行时才能创建符号链接。为什么会发生这种情况?
其次,当我尝试从 Windows 资源管理器打开这些符号链接时,出现此错误:
...Directory is not accessible. The Name Of The File Cannot Be Resolved By The System.
有没有更好的方法使用 Python 创建符号链接?如果没有,我该如何解决这个问题?
EDIT
这是for
在 album_linker 中循环:
def album_Linker(album_path, album_Genre, album_Style):
genre_basedir = "E:\Music\#02.Genre"
artist_basedir = "E:\Music\#03.Artist"
release_data_basedir = "E:\Music\#04.ReleaseDate"
for genre in os.listdir(genre_basedir):
genre_path = os.path.join(genre_basedir, "_" + album_Genre)
if not os.path.isdir(genre_path):
os.mkdir(genre_path)
album_Style_list = album_Style.split(', ')
print album_Style_list
for style in album_Style_list:
style_path = os.path.join(genre_path, "_" + style)
if not os.path.isdir(style_path):
os.mkdir(style_path)
album_path_list = album_path.split("_")
print album_path_list
#link_dst = unicode(os.path.join(style_path, album_path_list[2] + "_" + album_path_list[1] + "_" + album_path_list[0]))
link_dst = unicode(os.path.join(style_path, album_path))
link_src = unicode(album_path)
kdll = ctypes.windll.LoadLibrary("kernel32.dll")
kdll.CreateSymbolicLinkW(link_dst, link_src, 1)
它需要album_Genre
and album_Style
然后它在下面创建目录E:\Music\#02.Genre
。它还从脚本主体获取 album_path。这个 album_path 是我想在其下创建符号链接的目录路径E:\Music\#02.Genre\Genre\Style
。所以 album_path 是一个从另一个变量获取的变量for
在脚本主体中循环
for label in os.listdir(basedir):
label_path = os.path.join(basedir, label)
for album in os.listdir(label_path):
album_path = os.path.join(label_path, album)
if not os.path.isdir(album_path):
# Not A Directory
continue
else:
# Is A Directory
os.mkdir(os.path.join(album_path + ".copy"))
# Let Us Count
j = 1
z = 0
# Change Directory
os.chdir(album_path)