Script to Customize a Folder as Picture with Image File?
Script to Customize a Folder as Picture with Image File?
Hello, newbie here, and I'm fumbling with scripting, on a Windows 7 PC, XYplorer 18.90.0100.
I have a bunch of folders containing image files; is there some way to script a batch folder customization to set each selected folder to Type=Picture, and PictureFile=<folder>/00.jpg?
Any help would be greatly appreciated.
I have a bunch of folders containing image files; is there some way to script a batch folder customization to set each selected folder to Type=Picture, and PictureFile=<folder>/00.jpg?
Any help would be greatly appreciated.
Re: Script to Customize a Folder as Picture with Image File?
By doing what, changing / creating a desktop.ini file for each of them?
One of my scripts helped you out? Please donate via Paypal
Re: Script to Customize a Folder as Picture with Image File?
I had in mind using something along the lines of a simple batch-rename script, yet somehow passing parameters to change folder attributes accordingly. I think I see a capability of retrieving a next-in-line folder path, and the ability to form relative paths to address the folder's contents, and all my prime thumbnail files are named 00.jpghighend wrote:By doing what, changing / creating a desktop.ini file for each of them?
But if creating or modifying an existing folder ini file is doable, I could use some tips on how to go about it that way.
Re: Script to Customize a Folder as Picture with Image File?
Select the folders that should get a new desktop.ini file and run the script...
Code: Select all
foreach($folder, <get SelectedItemsPathNames <crlf>>, <crlf>, "e") {
if (exists("$folder\00.jpg") != 1) { continue; }
$desktopIni = $folder . "\desktop.ini";
$content = <<<>>>
[ViewState]
Logo=$folder\00.jpg
FolderType=Pictures
>>>;
writefile($desktopIni, $content, , "utf8");
attrstamp("hs", , $desktopIni);
}
status "Done...";
One of my scripts helped you out? Please donate via Paypal
Re: Script to Customize a Folder as Picture with Image File?
Highend,
Absolutely dandy, thank you very much. Oddly, I don't see any changes on refresh, but entering an altered folder and then backing one step up the tree shows the alterations of all. Definitely a huge time-saver. A donation will be forthcoming.
Absolutely dandy, thank you very much. Oddly, I don't see any changes on refresh, but entering an altered folder and then backing one step up the tree shows the alterations of all. Definitely a huge time-saver. A donation will be forthcoming.
Re: Script to Customize a Folder as Picture with Image File?
No problem and thanks for the donation!
One of my scripts helped you out? Please donate via Paypal
Re: Script to Customize a Folder as Picture with Image File?
Highend,
Your script worked well, until today. Now it is failing altogether.
The error message I get: "Resource does not contain any valid scripts. The script is terminating now."
I have been selecting Scripting->Load Script File, then Scripting->Run Script, which had been working flawlessly. I created my XYS file by copying from your post and pasting into notepad. I looked at the file contents, and didn't see any corruptions. I restarted XYplorer, and also restarted my computer.
Might this inexplicable failure be a result of my still using the 30-day trial version of XYplorer? I'm 4 or 5 days into my 30 now.
Your script worked well, until today. Now it is failing altogether.
The error message I get: "Resource does not contain any valid scripts. The script is terminating now."
I have been selecting Scripting->Load Script File, then Scripting->Run Script, which had been working flawlessly. I created my XYS file by copying from your post and pasting into notepad. I looked at the file contents, and didn't see any corruptions. I restarted XYplorer, and also restarted my computer.
Might this inexplicable failure be a result of my still using the 30-day trial version of XYplorer? I'm 4 or 5 days into my 30 now.
Re: Script to Customize a Folder as Picture with Image File?
No, it should work until your trial is over
Menu - Tools - Customize Toolbar...
Scroll down in the left list until you hit: User Button #<some number>
Choose the first available of such a button, select it, click the "Add ->" button
Hit the "OK" button
Right click that new button, "Edit..."
Copy this content into the clipboard (the part inside the code window):
Right click on the "Clear" button, "Paste Snippet"
Now the button's content should be populated as necessary.
Select your folders again, hit the button...
If something doesn't work, report back
Menu - Tools - Customize Toolbar...
Scroll down in the left list until you hit: User Button #<some number>
Choose the first available of such a button, select it, click the "Add ->" button
Hit the "OK" button
Right click that new button, "Edit..."
Copy this content into the clipboard (the part inside the code window):
Code: Select all
Snip: CTB 1
XYplorer 18.90.0102, 17.04.2018 13:42:04
Action
NewUserButton
Name
Create desktop.ini
Icon
:clip
ScriptL
foreach($folder, <get SelectedItemsPathNames <crlf>>, <crlf>, "e") {
if (exists("$folder\00.jpg") != 1) { continue; }
$desktopIni = $folder . "\desktop.ini";
$content = <<<>>>
[ViewState]
Logo=$folder\00.jpg
FolderType=Pictures
>>>;
writefile($desktopIni, $content, , "utf8");
attrstamp("hs", , $desktopIni);
}
status "Done...";
ScriptR
FireClick
0
Now the button's content should be populated as necessary.
Select your folders again, hit the button...
If something doesn't work, report back
One of my scripts helped you out? Please donate via Paypal
Re: Script to Customize a Folder as Picture with Image File?
The new button appears to work, but it does not create or change an INI file, or alter the folder view in any way.
I set the XYplorer attributes to run as an administrator, just to be sure it has all the necessary authorizations, and tried again; same results.
Your script used to produce:
[ViewState]
Logo=C:\Users\Hogwaump\Documents\Test\Macaques.jpg
FolderType=Pictures
While the Properties->Customize feature produces:
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=C:\Users\Hogwaump\Documents\Test\Macaques.jpg
Strangely, I can use the Properties->Customize feature from within XYplorer and get good results for one folder, yet from within Windows Explorer, the Customize tab no longer appears, which generally means a folder cannot be customized for some reason.
Screenshots of the contents of the new button:
I set the XYplorer attributes to run as an administrator, just to be sure it has all the necessary authorizations, and tried again; same results.
Your script used to produce:
[ViewState]
Logo=C:\Users\Hogwaump\Documents\Test\Macaques.jpg
FolderType=Pictures
While the Properties->Customize feature produces:
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=C:\Users\Hogwaump\Documents\Test\Macaques.jpg
Strangely, I can use the Properties->Customize feature from within XYplorer and get good results for one folder, yet from within Windows Explorer, the Customize tab no longer appears, which generally means a folder cannot be customized for some reason.
Screenshots of the contents of the new button:
Re: Script to Customize a Folder as Picture with Image File?
And you are 100% sure, that these selected folders really contain a picture named "00.jpg"?
Otherwise the creation of a desktop.ini is skipped for these folders!
Otherwise the creation of a desktop.ini is skipped for these folders!
Just edit the script to get the same...While the Properties->Customize feature produces:
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=C:\Users\Hogwaump\Documents\Test\Macaques.jpg
Code: Select all
$content = <<<>>>
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=$folder\00.jpg
>>>;
One of my scripts helped you out? Please donate via Paypal
Re: Script to Customize a Folder as Picture with Image File?
If Hogwaump doesn't actually have a 00.jpg image in each folder then he may want to consider having the script pull a random image from the folders. I did something similar but I used folder.jpg in lieu of desktop.ini only because I wanted to generate Zoom-to-Fill images for my folder thumbs as you can see here. viewtopic.php?f=7&t=15509
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
Re: Script to Customize a Folder as Picture with Image File?
This would take the first .jpg image from a folder (if 00.jpg) does NOT exist.
It would still skip the entire folder if no .jpg files are in it
And this would take a random .jpg file (and skips if none exist):
It would still skip the entire folder if no .jpg files are in it
Code: Select all
foreach($folder, <get SelectedItemsPathNames <crlf>>, <crlf>, "e") {
$image = "$folder\00.jpg";
if !(exists($image)) { $image = quicksearch("*.jpg /n /limit=1", $folder); }
if !(exists($image)) { continue; }
$desktopIni = $folder . "\desktop.ini";
$content = <<<>>>
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=$image
>>>;
writefile($desktopIni, $content, , "utf8");
attrstamp("hs", , $desktopIni);
}
status "Done...";
Code: Select all
foreach($folder, <get SelectedItemsPathNames <crlf>>, <crlf>, "e") {
$image = "$folder\00.jpg";
if !(exists($image)) {
$images = quicksearch("*.jpg /n", $folder);
$image = gettoken($images, rand(1, gettoken($images, "count", <crlf>)), <crlf>);
}
if !(exists($image)) { continue; }
$desktopIni = $folder . "\desktop.ini";
$content = <<<>>>
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=$image
>>>;
writefile($desktopIni, $content, , "utf8");
attrstamp("hs", , $desktopIni);
}
status "Done...";
One of my scripts helped you out? Please donate via Paypal
Re: Script to Customize a Folder as Picture with Image File?
Highend, Most of them do, and certainly the ones I have been working with in testing this. I still haven't figured out why a script that worked yesterday invariably blows up today, or why the button code seems to work yet does nothing. This is probably a matter for tech support to look at.highend wrote:And you are 100% sure, that these selected folders really contain a picture named "00.jpg"?
Otherwise the creation of a desktop.ini is skipped for these folders!
Re: Script to Customize a Folder as Picture with Image File?
For whatever reason, the first script in this post works as a button and as a script file, at least in the case of a 00.jpg file being present. I haven't tested it on a folder without a 00.jpg yet.highend wrote:This would take the first .jpg image from a folder (if 00.jpg) does NOT exist.
It would still skip the entire folder if no .jpg files are in itCode: Select all
. . .
Thanks for the fix.
Re: Script to Customize a Folder as Picture with Image File?
klownboy, thanks for the tip. I bookmarked that link for future use, once I know more about scripting.