Button to create a non-empty text file (e.g. 'desktop.ini')

Hello from Croatia,

I've been searching high and low for this one, and I appologize If there already is an answer available that I couldn't find.

Is there a way to create a button that creates a text file along with some text in it? I like to customize my folders using an icon file 'icon.ico', and It would be great to be able to have a button that creates a hidden 'desktop.ini' file that points to this icon and then sets a +R attribute on the folder itself, so the icon displays correctly.

Any thoughts on the subject would be much appreciated :slight_smile:

If it were me I'd just create one new file to use as a template and then copy/modify/move it as needed.

However you could create an Opus "MS_DOS Batch function" button with the following command to generate a new file containing some text.

echo This is some text>c:\file.txt

Adding to what John said, you can create a button or menu item which copies the template file to the current directory, asking for a new name, so it's similar to the usual templates in the New menu.

So, like one of Jon's suggestions:

<?xml version="1.0"?>
<button display="both" icon_size="large" label_pos="right">
	<label>Test Button</label>
	<tip>Test Button</tip>
	<function type="batch">
		<instruction>@runmode hide</instruction>
		<instruction>echo [.ShellClassInfo] &gt;{f}desktop.ini</instruction>
		<instruction>echo IconFile={dlgopen|Select Icon File...|%SystemRoot%\Icons\folder_blue_closed.ico} &gt;&gt;{f}desktop.ini</instruction>
		<instruction>echo IconIndex=0 &gt;&gt;{f}desktop.ini</instruction>
		<instruction>SetAttr FILE {f}desktop.ini ATTR=hs</instruction>
		<instruction>SetAttr FILE {f} ATTR=r</instruction>
		<instruction>Go REFRESH</instruction>

This button puts the customized icon info into a new desktop.ini of the "selected" folder (you can modify the button if you want it to function on the "current" folder). You also want to set the folder read-only, and then refresh the view in order to see your new icon. This button does all of that... it also uses {dlgopen} in order to prompt you to select the icon you want to use, and defaults to one on 'my' system - which you'll probably want to customize for your system...


1 Like

Thank you all very much.

steje, this is almost exactly what I was looking for.
Is there a way to insert an icon file name into 'desktop'ini' without the full path before it? I would like to use this customized folder on different computers, without the need to have centralized icons location, or having to change the 'desktop.ini' every time.

Ha... my first suggestion and what I was "going" to post was a simpler button that used a static path to an icon.

This is really a "desktop.ini" file question though. Of course you can make the button do whatever you want, but I'm not sure where you propose you'd be getting the icon from if NOT from a central location. Anyhow, you'd just need to replace the:

echo IconFile={dlgopen|Select Icon File...|%SystemRoot%\Icons\folder_blue_closed.ico} >>{f}desktop.ini

...portion of the button above with something generic like so:

echo IconFile=folder.ico >>{f}desktop.ini

...which seems to tell desktop.ini to look for an iconfile in the same directory you're assigning the icon to. I guess you'll have a way to GET the icon there first? Which you can add to the button as well of course...


NOTE: not sure if you actually TRIED the button code above, but just be aware that the first full button didn't just contain a full path to an icon, but also a dialog to let you BROWSE to the icon you want. The full path included just tells the dialog to use that file and path as the 'default' and to open the browse dialog to that folder already.

Anyhow, I'm curious how you intend to get the folder icon you want into each folder. It's got to come from "someplace" sort of "central-ish"... and while storage is plentiful nowadays, you'll have a bunch of those folder icons all over the place, in every folder you customize...

But... to each, his own :wink:...

Sorry for being off-topick-ish and thank you for that extra tweak.
Actually I was hoping for a way to include a browse dialog which then outputs just the filename of the icon, without the path in front of it, i.e. "folder.ico" and not "C:\Users\Owner\Documents\Project\folder.ico"

Putting it this way, I suppose the question gets more of a 'DOpus' flavour, but having looked through the forums I couldn't find a way to customize dlgopen's output. I guess that this is some sort of an external call to standard Windows open dialog..

I did try the button you posted, and the reason I asked for a way not to include path is simple. At my (advertising) company we have a bunch of clients that hire us to do different projects for them. Each project gets a folder (e.g. "CLIENT - Project") with its custom icon (usually a logo). We often share and/or exchange these folders and I think that this is the only efficient way in Windows to keep them permanently iconized.
What is more, having an icon in the project folder allows our OS X coworkers to use it to customize their display of folder/project icon.

Ah, well you can't control the output format of the {dlgopen} browse selection. In most any other scenario than what you're trying to do it might be sort of useless for the path NOT to be included. Though you could submit a feature request to GPSoft for a modified {dlgopen}...

The easiest way I think you can make this work 'now' is if you could justify using either a static name for the icon file (like logo.ico) - or perhaps base it's name on the client company name that you actually give the folder.

For instance, if you can standardize on your client folders (say Client1 as an example folder name) containing the logo with a similar name (say Client1_logo.ico), then the button can be made to expect that and write the desktop.ini info accordingly very easily.

If you still NEED to be able to browse and select, then you'd have to layer on some other kind of scripting glue to strip the path from the selected file...