Script to Customize a Folder as Picture with Image File?

Discuss and share scripts and script files...
Post Reply
Hogwaump
Posts: 8
Joined: 13 Apr 2018 23:02

Script to Customize a Folder as Picture with Image File?

Post by Hogwaump »

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.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to Customize a Folder as Picture with Image File?

Post by highend »

By doing what, changing / creating a desktop.ini file for each of them?
One of my scripts helped you out? Please donate via Paypal

Hogwaump
Posts: 8
Joined: 13 Apr 2018 23:02

Re: Script to Customize a Folder as Picture with Image File?

Post by Hogwaump »

highend wrote:By doing what, changing / creating a desktop.ini file for each of them?
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.jpg

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.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to Customize a Folder as Picture with Image File?

Post by highend »

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

Hogwaump
Posts: 8
Joined: 13 Apr 2018 23:02

Re: Script to Customize a Folder as Picture with Image File?

Post by Hogwaump »

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.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to Customize a Folder as Picture with Image File?

Post by highend »

No problem and thanks for the donation! :beer:
One of my scripts helped you out? Please donate via Paypal

Hogwaump
Posts: 8
Joined: 13 Apr 2018 23:02

Re: Script to Customize a Folder as Picture with Image File?

Post by Hogwaump »

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.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to Customize a Folder as Picture with Image File?

Post by highend »

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):

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
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
One of my scripts helped you out? Please donate via Paypal

Hogwaump
Posts: 8
Joined: 13 Apr 2018 23:02

Re: Script to Customize a Folder as Picture with Image File?

Post by Hogwaump »

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:
Button 1.jpg
Button 1.jpg (25.99 KiB) Viewed 4106 times
Button 2.jpg
Button 2.jpg (39.41 KiB) Viewed 4106 times

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to Customize a Folder as Picture with Image File?

Post by highend »

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!
While the Properties->Customize feature produces:
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=C:\Users\Hogwaump\Documents\Test\Macaques.jpg
Just edit the script to get the same...

Code: Select all

        $content = <<<>>>
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=$folder\00.jpg
>>>;
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Script to Customize a Folder as Picture with Image File?

Post by klownboy »

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

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to Customize a Folder as Picture with Image File?

Post by highend »

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

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...";
And this would take a random .jpg file (and skips if none exist):

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

Hogwaump
Posts: 8
Joined: 13 Apr 2018 23:02

Re: Script to Customize a Folder as Picture with Image File?

Post by Hogwaump »

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!
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.

Hogwaump
Posts: 8
Joined: 13 Apr 2018 23:02

Re: Script to Customize a Folder as Picture with Image File?

Post by Hogwaump »

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 it

Code: Select all

 . . .
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.

Thanks for the fix.

Hogwaump
Posts: 8
Joined: 13 Apr 2018 23:02

Re: Script to Customize a Folder as Picture with Image File?

Post by Hogwaump »

klownboy, thanks for the tip. I bookmarked that link for future use, once I know more about scripting.

Post Reply