通过修改desktop.ini更改图标的文件夹 [英] Changing an icon's folder by modifying desktop.ini

查看:924
本文介绍了通过修改desktop.ini更改图标的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是将每个文件夹的电影库图标更改为Windows中使用Java的每个文件夹的图标。

每个文件夹中都有一个256x256图标它以该文件夹命名,但具有适当的扩展名。
例如,名为 5cm Per Second 的文件夹中包含文件 5cm Per Second.ico



<我想我可以通过修改文件夹中的 desktop.ini 文件来做到这一点。所有的文件夹都有这个文件,因为每个文件夹中的图标都是文件夹的实际图标,但是当我更改了电影库的路径后, desktop.ini 中的图标路径没有得到更新。



每个 desktop.ini 看起来像这样:

 [。ShellClassInfo] 

IconResource = F:\Anime\Movies\5cm Per Second \5cm Per Second.ico,0

现在图标所在的路径是这样的:E:\Movies\5cm Per Second \ 5cm Per Second.ico 所以我想我所要做的就是将 desktop.ini 更改为:

  [。ShellClassInfo] 

IconResource = E:\Movies\5cm Per Second\5cm Per Second.ico,0

完全不起作用,我想我也应该让Windows知道 desktop.ini 是一个系统文件,我把这个添加到我的代码,但没有任何工作。



该示例文件夹的代码为:

  import java.io.File; 
import java.io.IOException;
import org.ini4j.Wini;

public class ListFiles {

public static void main(String [] args)throws IOException {

//目录路径
String path =E:\\Movies\\5cm Per Second;

字符串文件名;
文件夹=新文件(路径);
File [] listOfFiles = folder.listFiles(); (b)如果(listOfFiles [i] .isFile()){
if(ini)是

(int i = 0; i< listOfFiles.length; i ++) .equals(getExtension(listOfFiles [i])))
{
File theFile = listOfFiles [i];
Wini ini =新的Wini(theFile);
String iconPath = theFile.getParent()+.ico;
String field = iconPath +,0;
ini.put(。ShellClassInfo,IconResource,字段);
Runtime.getRuntime()。exec(attrib + H+ theFile.getAbsolutePath());




$ b public static String getExtension(File theFile){
String extension = null;
String fileName = theFile.getName();
int i = fileName.lastIndexOf('。'); (i> 0& i< fileName.length() - 1){
extension = fileName.substring(i + 1).toLowerCase();


}

if(extension == null){
return;
}
返回分机;






$你可以看到我编辑 IconResource 字段,我需要它使用 ini4j 库,然后我将 desktop.ini 的属性更改为隐藏和系统。

看起来这还不够,我真的不知道还有什么要做的。

解决方案

您不是在调用 ini.store() a>,这可能会将更改写入磁盘。

My goal is to change every folder's icon of my movie library to an icon I have for every folder in Windows using Java.

Every folder has a 256x256 icon in it named after the folder but with the appropriate extension. For example the folder called 5cm Per Second has the file 5cm Per Second.ico in it.

I figured I could do this by modifying the desktop.ini file in the folder. All the folders have that file in them because the icons inside each folder used to be the actual icon of the folder, but after I changed the path of my movie library the path of the icon in desktop.ini didn't get updated.

Every desktop.ini looks like this:

[.ShellClassInfo]

IconResource=F:\Anime\Movies\5cm Per Second\5cm Per Second.ico,0

Now the path of where the icon is at is this: E:\Movies\5cm Per Second\5cm Per Second.ico so I figured all I have to do is change the desktop.ini to this:

[.ShellClassInfo]

IconResource=E:\Movies\5cm Per Second\5cm Per Second.ico,0

That did not work at all then I figured I also should make Windows know that desktop.ini is a system file, I added this to my code but that did not work at all.

My code for that sample folder:

import java.io.File;
import java.io.IOException;
import org.ini4j.Wini;

public class ListFiles {

    public static void main(String[] args) throws IOException {

        // Directory path here
        String path = "E:\\Movies\\5cm Per Second";

        String fileName;
        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();

        for (int i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].isFile()) {
                if ("ini".equals(getExtension(listOfFiles[i])))
                {
                    File theFile = listOfFiles[i];
                    Wini ini = new Wini(theFile);
                    String iconPath = theFile.getParent() + ".ico";
                    String field = iconPath + ",0";
                    ini.put(".ShellClassInfo", "IconResource", field);
                    Runtime.getRuntime().exec("attrib +H " + theFile.getAbsolutePath());
                }
            }
        }
    }

    public static String getExtension(File theFile) {
        String extension = null;
        String fileName = theFile.getName();
        int i = fileName.lastIndexOf('.');

        if (i > 0 && i < fileName.length() - 1) {
            extension = fileName.substring(i + 1).toLowerCase();
        }

        if (extension == null) {
            return "";
        }
        return extension;
    }
}

As you can see I edit the IconResource field to the one I need it to be using ini4j library and then I change the attributes of desktop.ini to Hidden and System.

It looks like this is not enough and I really don't know what else to do.

解决方案

You are not calling ini.store(), which probably writes the change to disk.

这篇关于通过修改desktop.ini更改图标的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆