所以我有多个文件夹,其中包含一个名称相同的ico文件(封面)。我可以创建一个批处理脚本,它将获取目录中的所有文件夹并将其设置为其中的ico文件夹。我也可以创建一个脚本,它将执行相同的操作,但使用文件夹的快捷方式而不是文件夹本身。
答案 0 :(得分:0)
您可以尝试使用此批处理文件: Hackoo_Change_Icon_Folder.bat
@echo off
Title %~nx0 by Hackoo 2017
mode con cols=80 lines=3 & Color 9E
if _%1_==_Main_ goto :Main
:getadmin
echo(
echo "%~nx0" : Running Admin Shell
set vbs=%temp%\getadmin.vbs
(
echo Set UAC = CreateObject^("Shell.Application"^)
echo UAC.ShellExecute "%~s0", "Main %~sdp0 %*", "", "runas", 1
)> "%vbs%"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
goto :eof
::**********************************************************************************
:Main
set "fld=%userprofile%\Desktop\Hackoo"
set "ico=%~dp0icon.ico"
md "%fld%\icons" >nul 2>&1
echo(
echo Please wait a while... we execute the commands to change icon to the folder
If exist "%ico%" (
Attrib -s "%ico%"
) else (
cls & mode con cols=85 lines=3 & color 0C
echo(
echo The file "icon.ico" should be in the same folder as "%~nx0"
Timeout /T 5 /nobreak>nul & exit
)
if exist "%ico%" ( copy "%ico%" "%fld%\icons\icon.ico" /y >nul 2>&1 )
if exist "%fld%\desktop.ini" ( attrib -h -s -a "%fld%\desktop.ini" >nul 2>&1 )
(
echo [.ShellClassInfo]
echo IconResource=icons\icon.ico,0
)> "%fld%\Desktop.ini"
attrib +h +s +a "%fld%\Desktop.ini"
attrib +r "%fld%"
attrib +h "%fld%\icons"
Rem To refresh the explorer by killing and restart it
taskkill /im explorer.exe /f >nul & start explorer
If "%ErrorLevel%" EQU "0" (
cls & echo( & color 9E
echo The commands are executed successfully !
Timeout /T 4 /nobreak>nul
Explorer.exe /e,/root,"%fld%"
) else (
cls & echo( & color 0C
echo There was an error occured while this program is running !
Timeout /T 4 /nobreak>nul
)
答案 1 :(得分:0)
我做到了我终于做到了,这个项目结果是我讨价还价的方式,但我坚持不懈并让它发挥作用。所以现在我想与大家分享我写的所有脚本。我不得不将批处理文件和vbs文件结合起来,但是只要它工作就关心。
第一个脚本第1部分蝙蝠
@echo off
rem //comment - file name is FolderIconToCoverPart1Of2.bat
rem //comment – file name of part 2 vbs script is FolderIconToCoverPart2Of2.vbs
rem //comment - this batch file changes all the folders in its directory to use an ico file inside of themselves called cover.ico.
rem //comment - in windows icon information for a folder in stored in a hidden file inside of every folder called desktop.ini
rem //comment - in order for the folder to update its icon the desktop.ini file must be created somewhere else and then moved to the folder using a vbs script
rem //comment - bat files can't update a desktop.ini
rem //comment - The desktop.ini is created first in %temp% which refers to the temp folder for the current user
rem //comment - “C:\Users\UserName\AppData\Local\Temp”
rem //comment - for /D loops thorugh the folders
rem //comment - %%~fi & %%~fi% directs to the path of the current folder the loop is on with i being the variable declared in the loop itself
for /D %%i in (*) do (
rem //comment - checks if the desktop.ini exist if it does we need to change the attributes before editing it
rem //comment - If the desktop.ini does not exist the program will make a new file latter in the script
if exist "%temp%\desktop.ini" (
echo file found
attrib -h -s -r "%temp%\desktop.ini"
) else (
echo no file found makeing new one
)
rem //comment - end of if
echo setting icon in "%%~fi"
rem //comment - this sets the folder to make use of the desktop.ini file inside of it
attrib +r +s %%~fi
rem //comment - puts the new text into the desktop.ini file inside of the temp folder
rem //comment - if the file does not exist its makes a new one automatically
(echo [.ShellClassInfo]
echo IconResource=%%~fi\cover.ico) > "%temp%\desktop.ini"
rem //comment - passes arguments to vbs script
rem //comment - The arguments are the path of the current folder the loop is on and the path of the temp folder (were the desktop.ini is stored)
"FolderIconToCoverPart2Of2" "%%~fi" "%temp%
rem //comment - returns the desktop.ini file attributes to their original form
attrib +h +s -r %%~fi%\Desktop.ini
)
rem //comment - end of for loop
pause
第一个脚本第2部分vbs
rem //comment – file name is FolderIconToCoverPart2Of2.vbs
rem //comment – file name of part 1 bat file is FolderIconToCoverPart1Of2.bat
rem //comment - This vbs script is the second part of a batch script it has two argument passed to by that batch
rem //comment - The arguments are the path of the current folder the loop is on and the path of the temp folder (were the desktop.ini is stored)
rem //comment - creates an variable object that holds the arguments passed in by the batch
set args = Wscript.arguments
rem //comment - gets the first and second argument from args and holds them in variables
PathToFolder = args(0)
TempFolder = args(1)
rem //comment - converts Path to the temp folder to a string
rem //comment - then adds on the \Desktop.ini for a complete file path
TempDeskTopIni = CStr(TempFolder) + "\" + "Desktop.ini"
rem //comment - Not sure what this is I just know its needed
rem //comment - I think it has something to do with accessing methods built into the os itself (if anybody knows more pls tell me)
set shell = CreateObject ("Shell.Application")
rem //comment Creates and returns a folder object for the specified folder
set CurrentDirectory = shell.NameSpace( PathToFolder )
rem //comment - Takes the desktop.ini created in the temp folder and puts into the current directory the loop is on in the batch
CurrentDirectory.MoveHere TempDesktopIni, 4+16+1024
第二个脚本第1部分
@echo off
rem //comment - file name is ShortcutIconToCoverPart1Of2.bat
rem //comment – file name of part 2 vbs script is ShortcutIconToCoverPart2Of2.vbs
rem //comment - This batch file takes all the lnk shortcuts in its directory and changes there icon to a file called cover.ico inside of their target path
rem //comment - The actual changeing of the icon is done by a vbs script that has the current directory the loop is on passed to it as an argument
rem //comment - loops though all the files with the lnk extension and passes its path to the vbs script
rem //comment - %%~fi & %%~fi% directs to the path of the current folder the loop is on with i being the variable declared in the loop itself
for %%i in ("*.lnk") do (
echo file found changing icon to cover.ico %%~fi
rem //comment - pass the current lnk file the loop is on to the vbs script
"ShortcutIconToCoverPart2Of2" "%%~fi"
)
rem //comment - end of for loop
pause
第二个scropt第2部分vbs
rem //comment - file name is ShortcutIconToCoverPart2Of2.vbs
rem //comment – file name of part 1 bat script is ShortcutIconToCoverPart1Of2.bat
rem //comment - this vbs script takes the file path of a lnk passed to it and changes it icon to a file called cover.ico inside of its target path
rem //comment - creates an variable object that holds the arguments passed in by the batch
set args = Wscript.arguments
rem //comment - gets the first argument from args and holds it in the variable PathToLnk
PathToLnk = args(0)
rem //comment - Not sure what this is I just know its needed
rem //comment - I think it has something to do with accessing methods built into the os itself (if anybody knows more pls tell me)
Set sh = CreateObject("WScript.Shell")
rem //comment - saves the PathToLnk variable as a shortcut object
Set lnk = sh.CreateShortcut(PathToLnk)
rem //comment - sets the lnk variable icon path
lnk.IconLocation = lnk.TargetPath + "\cover.ico"
rem //comment - saves changes made to the lnk file with this script
lnk.Save