Jump to content
Sign in to follow this  
Achilles

Setting a folder's icon with autoit

Recommended Posts

Achilles

Here's what I've tried:

$dir = @DesktopDir
$name = 'Testing'
$ico = @AutoItExe

$pass = 6
If FileExists($dir & '\' & $name) then
    $pass = Msgbox(36, 'Warning', 'The directory you selected already exists. If you continue that directory will be deleted and recreated. Would you like to continue?')
EndIf

If $pass = 6 then
    If $name = '' then
        Msgbox(16, 'Error', 'You must enter a name for the project!')
    Else
        $pass = DirCreate($dir & '\' & $name)
        If $pass = 0 then
            Msgbox(16, 'Error', 'There was an error created the selected directory.')
        Else
            If FileExists($ico) then
                $file = FileOpen($dir & '\' & $name & '\desktop.ini', 2)
                FileWriteLine($file, '[.ShellClassInfo]')
                FileWriteLine($file, 'IconResource=' & $ico & ',0')
                FileClose($file)
                $a = FileSetAttrib($dir & '\' & $name & '\desktop.ini', 'HSA')
                Exit
            EndIf
        EndIf
    EndIf
EndIf
It creates the folder fine, it creates the file fine.. but it doesn't actually set the icon.. Any ideas?

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
KaFu

The trick seems to be this:

FileSetAttrib($parent_dir & '\' & $folder_to_create, "+S")

$parent_dir = @ScriptDir
$folder_to_create = 'Testing'
$iconfile_to_use = FileGetShortName(@AutoItExe)
$iconfile_to_use_icon_index = 0

If FileExists($parent_dir & '\' & $folder_to_create) Then
    If MsgBox(4 + 48, 'Warning', 'The directory you selected already exists. If you continue that directory will be deleted and recreated. Would you like to continue?') <> 6 Then Exit
    FileSetAttrib($parent_dir & '\' & $folder_to_create, "-R")
    FileDelete($parent_dir & '\' & $folder_to_create)
EndIf

If Not FileExists($iconfile_to_use) Then
    MsgBox(16, 'Error', 'The selected icon file does not exist?')
    Exit
EndIf

DirCreate($parent_dir & '\' & $folder_to_create)

If Not FileExists($parent_dir & '\' & $folder_to_create) Then
    MsgBox(16, "Error", "Error creating target dir.")
EndIf

$hFile = FileOpen($parent_dir & '\' & $folder_to_create & '\desktop.ini', 2 + 256)
If $hFile = -1 Then
    MsgBox(16, "Error", "Unable to open file desktop.ini.")
    Exit
EndIf
FileWrite($hFile, "[.ShellClassInfo]" & @CRLF & "IconFile=" & $iconfile_to_use & @CRLF & "IconIndex=" & $iconfile_to_use_icon_index & @CRLF)
FileClose($hFile)

FileSetAttrib($parent_dir & '\' & $folder_to_create, "+S")
FileSetAttrib($parent_dir & '\' & $folder_to_create & '\desktop.ini', '+SH')

Share this post


Link to post
Share on other sites
Achilles

The trick seems to be this:

FileSetAttrib($parent_dir & '\' & $folder_to_create, "+S")

$parent_dir = @ScriptDir
$folder_to_create = 'Testing'
$iconfile_to_use = FileGetShortName(@AutoItExe)
$iconfile_to_use_icon_index = 0

If FileExists($parent_dir & '\' & $folder_to_create) Then
    If MsgBox(4 + 48, 'Warning', 'The directory you selected already exists. If you continue that directory will be deleted and recreated. Would you like to continue?') <> 6 Then Exit
    FileSetAttrib($parent_dir & '\' & $folder_to_create, "-R")
    FileDelete($parent_dir & '\' & $folder_to_create)
EndIf

If Not FileExists($iconfile_to_use) Then
    MsgBox(16, 'Error', 'The selected icon file does not exist?')
    Exit
EndIf

DirCreate($parent_dir & '\' & $folder_to_create)

If Not FileExists($parent_dir & '\' & $folder_to_create) Then
    MsgBox(16, "Error", "Error creating target dir.")
EndIf

$hFile = FileOpen($parent_dir & '\' & $folder_to_create & '\desktop.ini', 2 + 256)
If $hFile = -1 Then
    MsgBox(16, "Error", "Unable to open file desktop.ini.")
    Exit
EndIf
FileWrite($hFile, "[.ShellClassInfo]" & @CRLF & "IconFile=" & $iconfile_to_use & @CRLF & "IconIndex=" & $iconfile_to_use_icon_index & @CRLF)
FileClose($hFile)

FileSetAttrib($parent_dir & '\' & $folder_to_create, "+S")
FileSetAttrib($parent_dir & '\' & $folder_to_create & '\desktop.ini', '+SH')

That did solve it... thanks for your help!

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.