获得目标路径下的所有文件的绝对路径
os.walk(path) os.walk()方法可以生成三元组,分别是是filepath,dirnames,filenames
for filepath,dirnames,filenames in os.walk(r'E:\test2'):
for filename in filenames:
print(os.path.join(filepath,filename))
批量修改文件夹下所有快捷方式
思路就是截取. 前面的作为新名字
import os
path = r"path"
for filepath,dirnames,filenames in os.walk(path):
for file in filenames:
if ".lnk" in file:
newname=file.split('.')[0]
os.rename(os.path.join(filepath,file),os.path.join(filepath,newname+'.lnk'))
参考:https://blog.csdn.net/qq_39721240/article/details/90704223
|