João Lagoas
João Lagoas

Reputation: 1

batch to attribute ico inside folder as new icon

I have a folder, and inside I have an .ico file that I want to set up as the icon to the main folder.

Here's my problem, if I do this manually and input this code

[.ShellClassInfo]
ConfirmFileOp=0  
NoSharing=1  
IconFile=folder.ico
IconIndex=0
InfoTip=Some sensible information.

in a desktop.ini file it works great.

But if a create a bat file with the following code it does not.

ECHO [.ShellClassInfo] >desktop.ini  
ECHO ConfirmFileOp=0 >>desktop.ini  
ECHO NoSharing=1 >>desktop.ini  
ECHO IconFile=folder.ico >>desktop.ini  
ECHO IconIndex=0 >>desktop.ini  
ECHO InfoTip=Some sensible information. >>desktop.ini 

The Output is exactly the same. I also assigned the +r to the folder because without it it doesn't work either way.

So what is wrong here?

Upvotes: 0

Views: 1481

Answers (1)

Yvon
Yvon

Reputation: 2993

It's due to several non-escaped special characters in your commands. If you run the batch first, then open desktop.ini to see its content, you'll find it's far from your expectation.

Problems:

  1. Excessive blank space at the end of each line.

    A appears on the left of >, which means an extra blank space to be added to the file.

    To solve this, simply remove this space. Like ECHO ConfirmFileOp=0>>desktop.ini.

  2. Un-escaped numbers

    ECHO ConfirmFileOp=0>>desktop.ini means write ConfirmFileOp= to the command window and pipe stdout to desktop.ini. 0 is a piping token.

    To solve this, escape the numbers by ^0, ^1 or so. Reference - Escape angle brackets in a Windows command prompt

    An easier way is by writing output redirecting instruction at the beginning of the line -

    >>desktop.ini echo ConfirmFileOp=0
    
  3. Improper file attributes

    desktop.ini should be hidden, system, and NOT archived. Reference - https://superuser.com/a/396051/333430 You can change the attributes of desktop.ini by adding the following line to the batch script:

    attrib desktop.ini -a +h +s
    

Upvotes: 1

Related Questions