Python Changing folder icon in desktop.ini via python

  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Python
AI Thread Summary
A Python program was created to generate a desktop.ini file in a specified folder and change its icon, but it initially failed to work. Key issues identified included the use of line endings; the program used "\n" which is suitable for Linux, while Windows requires "\r\n" for proper line breaks. The discussion highlighted the importance of verifying the desktop.ini file's format and suggested using a text editor to confirm functionality. Ultimately, the program worked after addressing the line ending issue. The conversation emphasized the utility of text mode ('wt') for handling local end-of-line conventions in file operations, particularly in Windows environments.
Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
I have created this python program to create a desktop.ini file in a test folder and then change the icon of it. However, the program is something like this

Code:
import os

desktop_ini = ["[.ShellClassInfo]\n",
     "IconResource=C:\\Users\\Arman\\Desktop\\Coding\\Desktop Icons\\directory_closed-5.ico,0\n",
     'FolderType=Generic']with open(r'C:\Users\Arman\Desktop\TestFolder\desktop.ini', 'w') as f:
    f.writelines(desktop_ini)
    f.close()os.system('attrib +s +h C:\\Users\\Arman\\Desktop\\TestFolder\\desktop.ini')
os.system('attrib +r C:\\Users\\Arman\\Desktop\\TestFolder')

but it's not working
 
Technology news on Phys.org
I would check the desktop.ini file to see if there's a CR LF after every line and that there is nothing more added to the file like blank lines...

In you program, you write a \n which is fine for linux but windows requires \r\n after lines.

Also does the writelines add a LF to the file?

Have you tried creating the desktop.ini file with an ordinary editor to verify that it works?
 
  • Like
Likes Arman777 and sysprog
jedishrfu said:
Have you tried creating the desktop.ini file with an ordinary editor to verify that it works?
It did not worked...Theres something wrong but I don't know what
 
jedishrfu said:
In you program, you write a \n which is fine for linux but windows requires \r\n after lines.
wait. It worked. Thanks a lot
 
For "transparent" handling of the local end-of-line convention when opening a file, text mode, i.e. 'wt' in your case, can be a useful option. In your case the program sounds like its specific for Windows making this less of an issue, but in other cases where the local OS doesn't matter text mode is a good choice for textual input/output. See more at https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such -conda create -n <env_name> python=3.7 ipykernel jupyter I am assuming this is successful as I can activate this environment via the anaconda prompt and following command -conda activate <env_name> Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted...

Similar threads

Back
Top