How to Check Both Panes for Existing Files?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

How to Check Both Panes for Existing Files?

Post by SkyFrontier »

Can someone tell me how can I check if a file (<curbase>) is present on both panes and:
-if YES, proceed execution of script;
-if NO, stop script.
Thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: How to Check Both Panes for Existing Files?

Post by serendipity »

SkyFrontier wrote:Can someone tell me how can I check if a file (<curbase>) is present on both panes and:
-if YES, proceed execution of script;
-if NO, stop script.
Thanks!
HINT:
From help:

Code: Select all

exists()
Checks whether a file or directory exists. 
Syntax 
exists(item) 
item: Full path (local or UNC) to a file system item. 
return: 0 = does not exist
1 = exists (file)
2 = exists (folder; drive; share; server) 

Examples
echo exists("C:\autoexec.bat"); //1 
echo exists("C:"); //2
echo exists("C:\"); //2
echo exists("C:\Windows"); //2
echo exists("C:\Windows\"); //2
echo exists("C:\*.bat"); //0 - wildcards are NOT recognized
Combine this with get "Item", [pane] and use IF.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: How to Check Both Panes for Existing Files?

Post by SkyFrontier »

IF only I knew it... :cry:
Thanks anyway, Serendipity!

-bug on forum engine: when trying to bold IF, it put the /b at the end of the whole sentence... :P
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: How to Check Both Panes for Existing Files?

Post by SkyFrontier »

@Serendipity:
I don't understand.
Here I posted a working version of an if/elseif/else-based script (is it bugged, perhaps...? Can't see nothing special).
But I'm yet to find a way to get this working on a much more simple stuff.
Here are some excerpts of code (enough to try and get results - not a single one working as intended, "a==a" > msg 1, "a==b" > msg 2.

Code: Select all

   $b = "<curname>";
   focus("pi");
   focus;
   selfilter "$b";
//   $check = exists("$b");
   if (Exists("$b")==0)  { echo "hi!"; };
//   elseif ($check = 0) { echo "hi!"; }
   else (Exists("$b")==1) { echo "Sorry - try again"; };

-------------

   $b = "<curname>";
   focus("pi");
   focus;
   $x = selfilter "$b";
//   $y = exists("$x");
   if ("$x"=="$b") {
   echo "hi!"
   }
   else {
   end ("$x"!="$b"), "Sorry - try again!";
   }

--------------

   $b = "<curname>";
   focus("pi");
   focus;
   $x = selfilter "$b";
//   $y = exists("$x");
   if ("$x"=="$b") {
   echo "hi!"
   }
   else {
   end ("$x"!="$b"), "Sorry - try again!";
   }
//   else {
//   end ($x =0), "Sorry - try again!";
//   }

--------------

   $b = "<curname>";
   focus("pi");
   focus;
   $x = selfilter "$b";
//   $y = exists("$x");
   if (Exists("$x")==0)  { echo "hi!"; };
//   elseif ($check = 0) { echo "hi!"; }
   else (Exists("$x")==1) { echo "Sorry - try again!"; };
Worst part is - all of this makes sense to me... :oops:
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

admin
Site Admin
Posts: 67271
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to Check Both Panes for Existing Files?

Post by admin »

SkyFrontier wrote:Can someone tell me how can I check if a file (<curbase>) is present on both panes and: ...
I think you want listpane(), not exists() for this job...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: How to Check Both Panes for Existing Files?

Post by SkyFrontier »

admin wrote:
SkyFrontier wrote:Can someone tell me how can I check if a file (<curbase>) is present on both panes and: ...
I think you want listpane(), not exists() for this job...
...there we go again... >sigh<
Thanks for the tip, Don! Hope that way I finally understand if/else/elseif... or perhaps is just the use of the improper command that was preventing the script to work.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: How to Check Both Panes for Existing Files?

Post by SkyFrontier »

:!: :mrgreen: :!:
...am I doing something absurdly stupid enough for this to work or is it really working after all?!

Code: Select all

   end (<xyver> < "9.70.0009"), "Sorry - this script requires XYplorer version 9.70.0009 or higher.<crlf>Click 'Ok' to exit.";
   $b = "<curname>";
   focus("pi");
   focus;
   $c = listpane(, "$b", 1 + 8);
   if (Exists("$c")==1)  { echo "hi!"; };
   else (Exists("$c")==0) { echo "Sorry - try again"; };
-is there a way to force it to work with <curbase> and NOT <curname>? Maybe fooling the system using the flag 2: NoFiles (= return only folders)? Is that safe?
>thank you!!!

EDIT: Reference:

Code: Select all

v9.70.0009 - 2010-11-12 12:30
    * SCs listfolder and listpane enhanced. Added flag to force the
      pattern to be an exact match, i.e. to suppress auto-adding of
      wildcards when no wildcards are contained in the pattern (aka
      "loose match").
        flags: (binary field)
          0: return folders and files with full paths [default]
          1: NoFolders (= return only files)
          2: NoFiles (= return only folders)
          4: NoPaths (= return the filenames without paths)
          8: NoAutoWildcards (= allow exact matches)
      Example:
        //list all folders that are named "code" in active pane
        ::inputselect("Test", listpane(, "code", 2 + 8));
EDIT 2: Added compatibility check code.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

admin
Site Admin
Posts: 67271
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to Check Both Panes for Existing Files?

Post by admin »

Please define "is present on both panes" and "exists". I think you are mixing categories.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: How to Check Both Panes for Existing Files?

Post by SkyFrontier »

A certain script (working on it - it performs perfectly, but it NEEDS this as an error handling method) requires to check if <curbase> is present on the opposite pane so it can continue. <curname> was used to deal with the existence of a same named file on both panes (solved with the list* implementation, but this script must also work if both panes has a same <curbase> named files.
Sorry, I really can't tell the conceptual difference among "present on both panes" and "exists" - except that "exists" has a crucial role to check whether a file is present on the other pane or not.

Code: Select all

Pane 1:
text.diz
Pane 2:
text.diz = script must apply to this file!
text.txt = to this file, too - even if "text.diz" is not present!
text for test.diz = ...and ignore this - if no "text.[b]ext[/b]" is found, stop script.
Thanks!
---
Reference:

Code: Select all

v7.90.0264 - 2009-05-13 13:04
    + Scripting got a new function.
      Name:   exists
      Action: Checks whether a file or directory exists.
      Syntax: exists(item)
        item: full path (local or UNC) to a file system item. 
        return: 0 = does not exist
                1 = exists (file)
                2 = exists (folder; drive; share; server)
      Examples:
        ::echo exists("C:\*.bat"); //0 - wildcards are NOT recognized
        ::echo exists("C:\autoexec.bat"); //1 
        ::echo exists("C:"); //2
        ::echo exists("C:\"); //2
        ::echo exists("C:\Windows"); //2
        ::echo exists("C:\Windows\"); //2
      Remarks:
        The API function used to determine the existence and nature of 
        the item is inherently tolerant with trailing spaces, and it 
        resolves relative syntax (\..\.. etc) before doing the check. 
        This was not my choice but there's no way to turn it off.
        Some of those special cases:
        ::echo exists("C:\autoexec.bat       "); //1 
        ::echo exists("C:\autoexec.bat\.."); //2 (!)
        ::echo exists("XYplorer.exe");  //1 (!)
        ::echo exists("appdata"); //2 (!) - if folder "appdata" is below 
                                           the current path (= xypath)
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

admin
Site Admin
Posts: 67271
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to Check Both Panes for Existing Files?

Post by admin »

Note that "present on a pane" and "exists" are different things. I cannot help you until you make up your mind about what you want. :)

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: How to Check Both Panes for Existing Files?

Post by SkyFrontier »

admin wrote:Note that "present on a pane" and "exists" are different things. I cannot help you until you make up your mind about what you want. :)
...so I assume my description of the *real* problem wasn't of any help, right?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

admin
Site Admin
Posts: 67271
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to Check Both Panes for Existing Files?

Post by admin »

SkyFrontier wrote:
admin wrote:Note that "present on a pane" and "exists" are different things. I cannot help you until you make up your mind about what you want. :)
...so I assume my description of the *real* problem wasn't of any help, right?
Well, no. I have no time to follow this.

This is all can give oyu now:
present on a pane -> listpane()
exsts in file system -> exists()

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: How to Check Both Panes for Existing Files?

Post by SkyFrontier »

Thank you, Don.
Posted the script here in case anyone is interested in the actual usage I have in mind for this.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: How to Check Both Panes for Existing Files?

Post by SkyFrontier »

Can someone please help me getting this to work?
Problem is with elseif syntax at the exists part.
Scenario: launch script with pane 2 active. Pane 1 must have something like: unins001.txt, unins000.diz; pane 2 must have: unins000.txt.
Expected result: echo "hi! IT WORKS!";

Code: Select all

   end (<xyver> < "9.70.0009"), "Sorry - this script requires XYplorer version 9.70.0009 or higher.<crlf>Click 'Ok' to exit.";
   $b = "<curname>";
   focus("pi");
   focus;
   $c = listpane(, "$b", 1 + 8);
   if (Exists("$c")==1)  { echo "hi!"; };
   elseif ($t= substr ($c, 0,-4); $c2 = listpane(, "$t", 1 + 8); (Exists("$c2")==1)) { echo "hi! IT WORKS!"; }
   else (Exists("$c")==0) { echo "Sorry - try again"; };
Thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: How to Check Both Panes for Existing Files?

Post by PeterH »

I don't understand this in several ways...

First: If/ElseIf/Else is one statement: so put no ; in between. (E.g. at end of the If-line.)
Second: ElseIf must, like If, specify what to compare, and then what to execute conditionally.
And third: Else can't have anything to compare - specifies only what to execute if neither If nor any ElseIf executed.

But as I said: I don't understand what you want to achieve, so can't be more specific.

Post Reply