PreviewFolder - Get a peek preview for folder contents

Discuss and share scripts and script files...
suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: PreviewFolder - Get a peek preview for folder contents

Post by suslo »

1. 'forking the whole script' is of course acceptable way for me
the thing is that i don't know how to add this most important feature (and removal of the icons too)
is it difficult? is it much time consuming?
will i be able to add it myself after your possible hints or little help?

this feature is present by default in a program called 'shell toys'. there the feature is named 'folder contents'
i'm trying to forget about several programs including 'shell toys' and take their best possibilities to xyplorer

3. i see all icons in a truncated (from the right and from the bottom) and low-quality way
just like they are displayed under the standard 'type stats and filter' button
these icons give me nothing but distraction. certainly it is a question of taste. i don't like such icons so i ask how can i hide them

4. thanks
6. i already changed that line:

Code: Select all

$stats   = foldersize(<curitem>, "<d> folders     <f> files", 0);
here my idea is to have/see no useless characters at all
but in this line the small problem is related not to letters but to figures from 0 to 9

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

Re: PreviewFolder - Get a peek preview for folder contents

Post by highend »

1. I don't know. Depends on your scripting skills, I'd say
Create an .ini file, populate it with entries for every file extension to act on, after selecting a file in the preview
menu, check it's file extension, compare it to the ones configures in the .ini, execute the belonging program

3.
Look at the regexes
E.g.:

Code: Select all

$files = regexreplace($files, "^(.*?$)(\r?\n|$)", "$q$1|<curitem>\$1$q moveto $q$dstFolder$q, $q<curitem>\$1$q;$lb");
It replaces a file name (without it's path)! with "the same" | <full path of it>
Because in a menu the pipe is the separator for: caption|icon, etc. and that's what is done here

6. Ofc it's related to 0-9 in that case, the first char matters. So use something that isn't allowed to exist, like
:, |, <, >, \. Any other first character can lead to the same problem, even ., !, ;, whatever, as long as you have any
file or folder that uses such a char as the first one in it's name
One of my scripts helped you out? Please donate via Paypal

suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: PreviewFolder - Get a peek preview for folder contents

Post by suslo »

Code: Select all

        if ($files) {
            if ($mode == 2) {
                $files = regexreplace($files, "^(.*?$)(\r?\n|$)", "$q$1|<curitem>\$1$q moveto $q$dstFolder$q, $q<curitem>\$1$q;$lb");
            } else {
                $files = openwith "C:\WINDOWS\system32\notepad.exe", s, "<curitem>";
            }
            $files = regexreplace($files, "^(.)_", "$1" . chr(31) . "__");
        }
where is the mistake in this variant?

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

Re: PreviewFolder - Get a peek preview for folder contents

Post by highend »

You know that <curitem> is the currently selected item in the pane, right? The script is called "PreviewFolder" so guess what you are trying to open with "openwith"... :ghost:
One of my scripts helped you out? Please donate via Paypal

suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: PreviewFolder - Get a peek preview for folder contents

Post by suslo »

Code: Select all

        if ($files) {
            if ($mode == 2) {
                $files = regexreplace($files, "^(.*?$)(\r?\n|$)", "$q$1|<curitem>\$1$q moveto $q$dstFolder$q, $q<curitem>\$1$q;$lb");
            } else {
                openwith "C:\WINDOWS\system32\notepad.exe";
            }
            $files = regexreplace($files, "^(.)_", "$1" . chr(31) . "__");
        }
this bad (and not working) variant opens the notepad at least

i read and re-read your posts attentively but many aspects are beyond my understanding at the moment
sorry if my replies look silly, it's not on purpose. my scripting skills are in their infancy

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

Re: PreviewFolder - Get a peek preview for folder contents

Post by highend »

I don't know what you are trying to achieve here. The "problem" is, that the script writes a new file that contains all the code that will be executed and then loads that file. XY will display it's content as menu entries and executes the code that is at the end of the line of a selected item afterwards

E.g.:
C:\Users\%USERNAME%\AppData\Local\Temp\~PreviewFolder.xys

Code: Select all

":Stats: 0 folder(s), 1 file(s) - Select|:tsf" end true
"-"
"XYplorer_18.90.0107_Install.exe|C:\Users\highend\AppData\Local\Temp\XYplorer_18.90.0107_Install.exe" goto "C:\Users\highend\AppData\Local\Temp\XYplorer_18.90.0107_Install.exe";
So depending on the $mode (and you should use a new one here...), you need to use your openwith line there...
One of my scripts helped you out? Please donate via Paypal

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

Re: PreviewFolder - Get a peek preview for folder contents

Post by highend »

An example:

Code: Select all

":Stats: 0 folder(s), 2 file(s) - Select|:tsf" end true
"-"
"XY_External renamer.exe|C:\Users\%USERNAME%\AppData\Local\Temp\XY_External renamer.exe" global $file = "C:\Users\%USERNAME%\AppData\Local\Temp\XY_External renamer.exe"; sub "_Execute";
"opera_crashreporter.log|C:\Users\%USERNAME%\AppData\Local\Temp\opera_crashreporter.txt" global $file = "C:\Users\%USERNAME%\AppData\Local\Temp\opera_crashreporter.txt"; sub "_Execute";

"_Execute"
    global $file;
    $ext = gpc($file, "ext");
    switch ($ext) {
        case "txt":
            openwith "notepad", , $file; break;
        case "exe":
            open $file; break;
        //case "..."
        case default:
            //<do whatever...>;
    }
In other words:
The part behind "caption|icon" must be rewritten to:

Code: Select all

global $file = "C:\Users\%USERNAME%\AppData\Local\Temp\XY_External renamer.exe"; sub "_Execute";
And then you need to append this part to the "~PreviewFolder.xys" file:

Code: Select all

"_Execute"
    global $file;
    $ext = gpc($file, "ext");
    switch ($ext) {
        case "txt":
            openwith "notepad", , $file; break;
        case "exe":
            open $file; break;
        //case "..."
        case default:
            //<do whatever...>;
    }
The "_Execute" section is hidden from the menu that is invoked...
One of my scripts helped you out? Please donate via Paypal

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

Re: PreviewFolder - Get a peek preview for folder contents

Post by highend »

Another example (I just realized that you are even able to use user defined functions in this special case of a XY script):

Code: Select all

":Stats: 0 folder(s), 2 file(s) - Select|:tsf" end true
"-"
"XY_External renamer.exe|R:\XY_External renamer.exe" handleFile("R:\XY_External renamer.exe");
"opera_crashreporter.log|R:\opera_crashreporter.txt" handleFile("R:\opera_crashreporter.txt");

function handleFile($file) {
    $ext = gpc($file, "ext");
    switch ($ext) {
        case "txt":
            openwith "notepad", , $file; break;
        case "exe":
            open $file; break;
        //case "..."
        case default:
            //<do whatever...>;
    }
}
A bit shorter than the example in the last posting...
One of my scripts helped you out? Please donate via Paypal

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

Re: PreviewFolder - Get a peek preview for folder contents

Post by klownboy »

Hey highend, that could be handy using case in a function. One place that immediately came to mind is WhiteSpaceCtxMenu script viewtopic.php?f=7&t=13831 where the menu(s) that display are based on the file extension of the highlighted file.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

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

Re: PreviewFolder - Get a peek preview for folder contents

Post by highend »

Yeah but it also limits the script to a minimum version, in this case v17.30.0002 (where the switch logic was implemented). I normally tend to avoid that although that's not always possible...

Imho this is still the wrong way to do it, an .ini file with a section "Extensions" and each line consists of (joined) file extensions together with a belonging application. Easier to maintain, more flexible, multiple extensions for one application supported...

I just wanted to show a way how this can be achieved. My internal version works differently...
One of my scripts helped you out? Please donate via Paypal

suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: PreviewFolder - Get a peek preview for folder contents

Post by suslo »

i only understood some tiny pieces (in many or all cases i may be wrong, of course):

"C:\Users\%USERNAME%\AppData\Local\Temp\~PreviewFolder.xys"
there is no need to create another xys-file since we already have the ~.xys file. is it correct?

"depending on the $mode (and you should use a new one here...)"
i have to change $mode = 1 to $mode = 3

"":Stats: 0 folder(s), 1 file(s) - Select|:tsf" end true"
i don't know what to do with this line and where to place it in the script

""-""
i don't understand the meaning of this line

"XYplorer_18.90.0107_Install.exe"
should i change this (and similar) line to notepad.exe?

"opera_crashreporter.log"
how should i use this example containing the 'opera', 'log', 'txt' words?

"The part behind "caption|icon" must be rewritten"
do you mean all these lines? (when saying 'part'):

Code: Select all

":Stats: 0 folder(s), 2 file(s) - Select|:tsf" end true
"-"
"XY_External renamer.exe|R:\XY_External renamer.exe" handleFile("R:\XY_External renamer.exe");
"opera_crashreporter.log|R:\opera_crashreporter.txt" handleFile("R:\opera_crashreporter.txt");

function handleFile($file) {
    $ext = gpc($file, "ext");
    switch ($ext) {
        case "txt":
            openwith "notepad", , $file; break;
        case "exe":
            open $file; break;
        //case "..."
        case default:
            //<do whatever...>;
    }
}
"then you need to append this part to the "~PreviewFolder.xys" file"
so should i need to add the code that will create the ~PreviewFolder.xys file? should i keep the already existing ~.xys file in the code?

(when saying 'append') do you mean to place these lines inside of the ~PreviewFolder.xys file?:

Code: Select all

"_Execute"
    global $file;
    $ext = gpc($file, "ext");
    switch ($ext) {
        case "txt":
            openwith "notepad", , $file; break;
        case "exe":
            open $file; break;
        //case "..."
        case default:
            //<do whatever...>;
    }
do you also mean that i should add the following lines? (to beginning of the ~PreviewFolder.xys file)

Code: Select all

[Extensions]
*.txt|*.cue|*.log|*.exe|*.png

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

Re: PreviewFolder - Get a peek preview for folder contents

Post by highend »

"C:\Users\%USERNAME%\AppData\Local\Temp\~PreviewFolder.xys"
there is no need to create another xys-file since we already have the ~.xys file. is it correct?
It is written by the script, yes. Another .xys file? Not necessary
"depending on the $mode (and you should use a new one here...)"
i have to change $mode = 1 to $mode = 3
I wouldn't change the mode, I would define a new one. Preferable 3
"":Stats: 0 folder(s), 1 file(s) - Select|:tsf" end true"
i don't know what to do with this line and where to place it in the script
?
""-""
i don't understand the meaning of this line
It is a menu item separator
"XYplorer_18.90.0107_Install.exe"
should i change this (and similar) line to notepad.exe?
These were just example files that existed in the directory I used the script on...
"opera_crashreporter.log"
how should i use this example containing the 'opera', 'log', 'txt' words?
What? opera isn't even a file extension...
"The part behind "caption|icon" must be rewritten"
do you mean all these lines? (when saying 'part'):
For the lines that need to execute some command
In this case:

Code: Select all

"XY_External renamer.exe|R:\XY_External renamer.exe" handleFile("R:\XY_External renamer.exe");
"opera_crashreporter.log|R:\opera_crashreporter.txt" handleFile("R:\opera_crashreporter.txt");
"then you need to append this part to the "~PreviewFolder.xys" file"
so should i need to add the code that will create the ~PreviewFolder.xys file? should i keep the already existing ~.xys file in the code?

(when saying 'append') do you mean to place these lines inside of the ~PreviewFolder.xys file?:
Yes / Yes / Yes

Or as an alternative way, forget about the ~PreviewFolder.xys file and do everything inside the PreviewFolder.xys file
and use a popupmenu / popupnested to display everything.
do you also mean that i should add the following lines? (to beginning of the ~PreviewFolder.xys file)
Em, no! I was talking about an .ini file. Such entries do not belong into a .xys file!
One of my scripts helped you out? Please donate via Paypal

Post Reply