Shell Script for modifying desktop.ini file

1.2k views Asked by At

I have many folders with custom icons. All the folders are present in same directory.
For eg. D:\Folder is the directory which contains folder1, folder2, ..... etc.
And each folder contain their respective icon and desktop.ini files

The contents of current desktop.ini file are as follows:

[.ShellClassInfo]
ConfirmFileOp=0
NoSharing=1
IconFile=folder1.ico
IconIndex=0
InfoTip=folder1

I want to remove NoSharing=1 from each folder's desktop.ini file.

After Removal the ini file should look like :

[.ShellClassInfo]
ConfirmFileOp=0
IconFile=folder1.ico
IconIndex=0
InfoTip=folder1

The ini file is hidden and has attributes : system, hidden and archive.
Thanks for any help you may be able to provide.

2

There are 2 answers

3
Quanmao On BEST ANSWER

Just 1 command: Recursively(-r) replace/remove NoSharing=1 line in each desktop.ini files in D:\Folder

msr -r -p D:\Folder -f "^desktop.ini$" -S -t "(\s+)NoSharing=1\s*" -o "$1" -R

  • If you want to preview colorful replacing result, remove -R
  • If you want to backup changed files, add -K like -R -K or -RK
  • You can also filter by file name, directory name, size range, last write time range, etc., just run the exe to show built-in usages and docs, or see git docs like README.md

msr.exe/msr.gcc*/msr.cygwin is a single exe tool (about 1.6MB, no dependencies, with cross platform versions on Windows and Linux) to find and replace files or pipe text recursively and support backup: in my open project https://github.com/qualiu/msr tools directory.

Replace files

3
agc On

Use sed to print every line except the unwanted line, on all the filenames, (MS Windows style pathnames), with in-place editing and backup files:

sed --in-place=.bak --quiet '/^NoSharing=1$/!p' D:\Folder\folder?\desktop.ini

(Remove the =.bak if backups aren't needed.)