简体   繁体   English

批处理脚本 - 更改桌面上文件夹的图标 (Windows XP)

[英]Batch Script - Change Icon of a Folder on Desktop (Windows XP)

How would I go about changing a desktop folder's icon/image via the command line/batch script in windows xp?我将如何通过 windows xp 中的命令行/批处理脚本更改桌面文件夹的图标/图像?

I will be creating an event in one of my scripts to change the icon to an image of an exclamation point when a new file is inserted into a folder to alert users.我将在我的一个脚本中创建一个事件,以在将新文件插入文件夹以提醒用户时将图标更改为感叹号的图像。

Save your image.ico to desktop.将您的 image.ico 保存到桌面。
The following will make a test folder on the desktop as well as the desktop.ini file linking the image file you wish to use.以下将在桌面上创建一个测试文件夹以及链接您希望使用的图像文件的 desktop.ini 文件。

CD "%userprofile%\desktop"
MKDIR "TEST FOLDER"
ATTRIB +s "TEST FOLDER"
CD "TEST FOLDER"
COPY /Y "%userprofile%\desktop\image.ico" "./image.ico"
ECHO [.ShellClassInfo] >> desktop.txt
ECHO ConfirmFileOp=0 >> desktop.txt
ECHO NoSharing=1 >> desktop.txt
ECHO IconFile=image.ico >> desktop.txt
ECHO IconIndex=0 >> desktop.txt
ECHO InfoTip= >> desktop.txt
CHCP 1252 >NUL
CMD.EXE /D /A /C (SET/P=ÿþ)<NUL > desktop.ini 2>NUL
CMD.EXE /D /U /C TYPE desktop.txt >> desktop.ini
DEL /F /Q desktop.txt
ATTRIB +S +H desktop.ini image.ico

The image shows up instantaneously as long as it is a new folder (not one that was deleted and recreated. You just 'mkdir' a folder that was recently deleted, the desktop will need to be refreshed to see the changes (caching?).只要它是一个新文件夹(不是被删除并重新创建的文件夹),图像就会立即显示出来。您只需“mkdir”一个最近删除的文件夹,需要刷新桌面才能看到更改(缓存?)。

Answer by "Mechaflash" didn't work for me on my system (Windows XP SP3). “Mechaflash”的回答在我的系统(Windows XP SP3)上对我不起作用。 . . . . but this worked:但这有效:
Open a work folder and drop an icon inside it ("Desktop.ini.ico") and this batch file:打开一个工作文件夹并在其中放置一个图标(“Desktop.ini.ico”)和这个批处理文件:

@ECHO OFF  
PUSHD "%~dp0"  
MKDIR "NEW CUSTOM FOLDER"  
ATTRIB -R "NEW CUSTOM FOLDER"  
ATTRIB -H -R "NEW CUSTOM FOLDER\Desktop.ini.ico"  
ATTRIB -H -R "NEW CUSTOM FOLDER\Desktop.ini"  
COPY /Y "Desktop.ini.ico" "NEW CUSTOM FOLDER\Desktop.ini.ico"  
ECHO [.ShellClassInfo] > "NEW CUSTOM FOLDER\Desktop.ini"  
ECHO IconFile=Desktop.ini.ico >> "NEW CUSTOM FOLDER\Desktop.ini"  
ECHO IconIndex=0 >> "NEW CUSTOM FOLDER\Desktop.ini"  
ECHO InfoTip=This folder InfoTip text is inside "Desktop.ini" >> "NEW CUSTOM FOLDER\Desktop.ini"  
ATTRIB +H +R "NEW CUSTOM FOLDER\Desktop.ini.ico"  
ATTRIB +H +R "NEW CUSTOM FOLDER\Desktop.ini"  
ATTRIB +R "NEW CUSTOM FOLDER"  
POPD  
EXIT  

Double-click the batch file and voila, there is your "NEW CUSTOM FOLDER" inside your work folder.双击批处理文件,瞧,您的工作文件夹中有“新自定义文件夹”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM