利用win32com.shellshellcon()获取Windows系统常用特殊文件夹路径
win32com.shell.shellcon模块是一个Windows shell常量模块,提供了一些特殊文件夹的常量和路径常量。可以使用这些常量和路径来获取Windows系统中常用的特殊文件夹路径。
以下是一些常用的特殊文件夹和它们的路径及其使用示例:
1. 桌面文件夹(Desktop):
- 常量:win32com.shell.shellcon.CSIDL_DESKTOP
- 路径:win32com.shell.shell.SHGetSpecialFolderPath(0, win32com.shell.shellcon.CSIDL_DESKTOP, None, 0)
- 使用示例:
import win32com.shell.shell as shell
import win32com.shell.shellcon as shellcon
desktop_path = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_DESKTOP, None, 0)
print("桌面文件夹路径:", desktop_path)
2. 我的文档文件夹(My Documents):
- 常量:win32com.shell.shellcon.CSIDL_PERSONAL
- 路径:win32com.shell.shell.SHGetSpecialFolderPath(0, win32com.shell.shellcon.CSIDL_PERSONAL, None, 0)
- 使用示例:
import win32com.shell.shell as shell
import win32com.shell.shellcon as shellcon
my_documents_path = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
print("我的文档文件夹路径:", my_documents_path)
3. 我的图片文件夹(My Pictures):
- 常量:win32com.shell.shellcon.CSIDL_MYPICTURES
- 路径:win32com.shell.shell.SHGetSpecialFolderPath(0, win32com.shell.shellcon.CSIDL_MYPICTURES, None, 0)
- 使用示例:
import win32com.shell.shell as shell
import win32com.shell.shellcon as shellcon
my_pictures_path = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_MYPICTURES, None, 0)
print("我的图片文件夹路径:", my_pictures_path)
4. 开始菜单文件夹(Start Menu):
- 常量:win32com.shell.shellcon.CSIDL_STARTMENU
- 路径:win32com.shell.shell.SHGetSpecialFolderPath(0, win32com.shell.shellcon.CSIDL_STARTMENU, None, 0)
- 使用示例:
import win32com.shell.shell as shell
import win32com.shell.shellcon as shellcon
start_menu_path = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_STARTMENU, None, 0)
print("开始菜单文件夹路径:", start_menu_path)
5. 系统文件夹(Windows):
- 常量:win32com.shell.shellcon.CSIDL_WINDOWS
- 路径:win32com.shell.shell.SHGetSpecialFolderPath(0, win32com.shell.shellcon.CSIDL_WINDOWS, None, 0)
- 使用示例:
import win32com.shell.shell as shell
import win32com.shell.shellcon as shellcon
windows_path = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_WINDOWS, None, 0)
print("系统文件夹路径:", windows_path)
通过使用win32com.shell.shellcon提供的常量和路径,可以方便地获取Windows系统中常用特殊文件夹的路径,并在程序中使用这些路径进行文件或文件夹的操作。
