Script Request - File Selector

Discuss and share scripts and script files...
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Script Request - File Selector

Post by SkyFrontier »

Can someone script-talented please write a simple script to read a .txt file containing a list of local/web files, if none specified then read the clipboard and after that selecting then on file list, eventually writing a customizable report regarding those files (previously set on the script itself; no GUI needed here) on a .txt file or at least pasting such report into clipboard ant telling user about that completion?

Key: such script must translate URLs/local paths such

C:\Temp\AiRoboForm-beta.exe
http://www.roboform.com/dist/AiRoboForm ... e-beta.exe

into

AiRoboForm-beta.exe
AiRoboForm-Portable-beta.exe

thus cleaning/ignoring everything prior to the last "/" or "\".

-Useful to easily select recent downloaded files of a given job out of FlashGet default download folder, without having to set endless default locations to it each and every time.

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

vegard
Posts: 76
Joined: 31 Jan 2010 15:45
Location: Sandnes, Norway

Re: Script Request - File Selector

Post by vegard »

SkyFrontier wrote: thus cleaning/ignoring everything prior to the last "/" or "\".
I'm not going to try and understand your run-on sentences, but you will want to look into regular expressions.
This would do the trick: /^.*(/|\)(.*)$/$1

Also give regexbuddy a try.

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

Re: Script Request - File Selector

Post by SkyFrontier »

-unable to code-

I usually adapt code I find here or crash into XYwiki/help/History.txt just to solve small problems.

For now, regex/coding is out of question. Yeah, I hate to pay the price for not knowing it... One day or another forum regulars come up and give a hand. Trying to find some time and gather those scripts spread around 4 macinhes/several installments/thousands of backup CDs and make them available here. This may help people who probably rush into similar problems as mine and avoid them the all the headache I went into.

Thanks for the hint!
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...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script Request - File Selector

Post by Stefan »

May you want to describe again what you wanna do in short words and lines?

- What do you have,
- how looks the content of that txt,
(show an example here)

- what should happens,
(show an example here)

- which way of output do you want
- and how should that look-a-like?
(show an example here)

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

Re: Script Request - File Selector

Post by SkyFrontier »

I have a .txt containing this:

Code: Select all

http://www.roboform.com/dist/AiRoboForm-Portable-beta.exe
C:\Temp\AiRoboForm-beta.exe
(optionally this could be read out of cliboarded content, no need to read any .txt as a base)
I need a script to clean it out resulting as this

Code: Select all

AiRoboForm-beta.exe
AiRoboForm-Portable-beta.exe
into clipboard, plus reading focused XY file list (active pane) against this clipboarded list and selecting only those 2 files among dozens of other files, displayed in that same XY files list. So I can easily move/copy/backup only those 2 files instead of scrolling entire list looking after them.
Hope this helps to help me and others!

Huh... Stefan, can you please try to help on this matter, too?
Problem is similar to what Ysl faced. Your script doesn't work anymore (probably due to recent changes on XY scripting) so I can't check if it helps me out.
This solves a bit:

Code: Select all

"Create Those Folders"
  //Get Location of where Folders will be created.
  $dir=InputFolder("<curpath>", "Where would you like to create these folders?");
  //Generate and execute a script to create each new item.
  Load(Report("New('$dir\{Name}','dir');"),, "s");
(TheQwerty code).
Problem is: a) it copies ALL contents of a folder as a base name (and I'd like to have only selected files as a base for new empty folders; b) it results in folders with extensions, having to polite each and every one to make them usable!

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

vegard
Posts: 76
Joined: 31 Jan 2010 15:45
Location: Sandnes, Norway

Re: Script Request - File Selector

Post by vegard »

You could've at least used the help...
report()
Returns a report of the current file list contents.
Syntax
onlyselected
0: [default] report all current list items
1: report all currently selected list items
header
Any string data to be put at the top of output.
footer
Any string data to be put at the bottom of output.
return
The report.
regexreplace()
Replace parts of a string, using a regular expression pattern.
Syntax
regexreplace(string, pattern, replacement, [matchcase])
string String to work on (haystack).
pattern The regexp pattern to search for in string (needle).
replacement String to replace with.
matchcase [Defaults to 0] Compare method.
0: A=a
1: A<>a
return The new string.
So your regex (for files only) is: ^.*\\(?:(.*)\..*)|(.*)$
And you will want to use the flag onlyselected.

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

Re: Script Request - File Selector

Post by SkyFrontier »

Dear Vegard,

That's greek to me! :oops:
Help doesn't help if you don't know where to look for.

Very simple changes like this I am able to produce, or sequences involving simpler script commands plus command IDs. Sorry to disappoint you.

As far as I can see in the above code, I can't even tell you where regex should go. I see none, as it is, so can't even try-an-error variants based on what you pointed.
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: Script Request - File Selector

Post by SkyFrontier »

As example: tried to replace "{name}" with "^.*\\(?:(.*)\..*)|(.*)$".
The result you ca predict.
Don't laugh - it's true! :lol:
XYscripting is like a space shuttle on the hands of an ape, to me. And I can't live without it! :mrgreen:
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...

vegard
Posts: 76
Joined: 31 Jan 2010 15:45
Location: Sandnes, Norway

Re: Script Request - File Selector

Post by vegard »

I'm not familiar with the scripting syntax, but I would have done something like this:

Code: Select all

Load(Report("New('$dir\regexreplace({Name},^.*\\(?:(.*)\..*)|(.*)$, $1,)','dir');"),1, "s");

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

Re: Script Request - File Selector

Post by SkyFrontier »

Didn't work, Vegard. Thanks for trying.
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...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script Request - File Selector

Post by Stefan »

SkyFrontier wrote:I have a .txt containing this:

Code: Select all

http://www.roboform.com/dist/AiRoboForm-Portable-beta.exe
C:\Temp\AiRoboForm-beta.exe
(optionally this could be read out of cliboarded content, no need to read any .txt as a base)
I need a script to clean it out resulting as this

Code: Select all

AiRoboForm-beta.exe
AiRoboForm-Portable-beta.exe
into clipboard, plus reading focused XY file list (active pane) against this clipboarded list and selecting only those 2 files among dozens of other files, displayed in that same XY files list. So I can easily move/copy/backup only those 2 files instead of scrolling entire list looking after them.
Hope this helps to help me and others!
I will try it:

Untested.

Code: Select all

$dummy = "";

//*************************************************
//  I have a .txt containing this:
//  http://www.roboform.com/dist/AiRoboForm-Portable-beta.exe
//  C:\Temp\AiRoboForm-beta.exe
//*************************************************
    $TextFile = readfile("C:\Temp\a.txt");




//*************************************************
//  (optionally this could be read out of cliboarded content, 
//  no need to read any .txt as a base)
//*************************************************
    //$TextFile = "<clipboard>";



//*************************************************
    $Line1 = gettoken($TextFile, 1, "<crlf>");
    $Line2 = gettoken($TextFile, 2, "<crlf>");
 



//*************************************************
//  I need a script to clean it out resulting as this
//  AiRoboForm-Portable-beta.exe
//  AiRoboForm-beta.exe
//*************************************************
//now i could use gettoken($TextFile, -1, "/");  again ;-)
    $URL1 = regexreplace($Line1,".+/(.+)","$1");
    $URL2 = regexreplace($Line2,".+\\(.+)","$1");

 
 

//*************************************************
//  into clipboard,

//  Why?, That's not needed for this script to work:
//    copy $URL1;
//    copy $URL1;
//*************************************************
  



 

//*************************************************
//  plus reading focused XY file list (active pane) against this clipboarded list 
// and selecting only those 2 files among dozens of other files, displayed in that same XY files list.
//  selfilter [pattern], [type (f|d)], [column], [add]
    selfilter """$URL1""";
    selfilter """$URL2""",,1;
  
 
//
Try this, than we go an step ahead if needed.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script Request - File Selector

Post by Stefan »

And please don't mix-up threads.
Your second question we can discuss in that other thread http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=4212
Post there exactly what problem you have whit which script. What happens and what should be.


500

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

Re: Script Request - File Selector

Post by SkyFrontier »

No go.
Did this:

Code: Select all

    $TextFile = readfile("C:\Temp\a.txt");
    $TextFile = "<clipboard>";
    $Line1 = gettoken($TextFile, 1, "<crlf>");
    $Line2 = gettoken($TextFile, 2, "<crlf>");
    $URL1 = regexreplace($Line1,".+/(.+)","$1");
    $URL2 = regexreplace($Line2,".+\\(.+)","$1");
    selfilter """$URL1""";
    selfilter """$URL2""",,1;
No matter creating a "C:\Temp\a.txt" or copying desired files' paths (to be read from clipboard, then cleansed, then selected out of tens of files), it only produces a step check then stops doing nothing.
-"Line1" and "Line2" are generic codes to deal with URL/local paths, right? This code is meant to be a generic file selector for no matter how much "file addressees" are contained inside clipboard/a.txt...
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...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script Request - File Selector

Post by Stefan »

SkyFrontier wrote:No go.
Did this:

Code: Select all

    $TextFile = readfile("C:\Temp\a.txt");
    $TextFile = "<clipboard>";
    $Line1 = gettoken($TextFile, 1, "<crlf>");
    $Line2 = gettoken($TextFile, 2, "<crlf>");
    $URL1 = regexreplace($Line1,".+/(.+)","$1");
    $URL2 = regexreplace($Line2,".+\\(.+)","$1");
    selfilter """$URL1""";
    selfilter """$URL2""",,1;
No matter creating a "C:\Temp\a.txt" or copying desired files' paths (to be read from clipboard, then cleansed, then selected out of tens of files), it only produces a step check then stops doing nothing.
-"Line1" and "Line2" are generic codes to deal with URL/local paths, right? This code is meant to be a generic file selector for no matter how much "file addressees" are contained inside clipboard/a.txt...

1.) $TextFile comes from an file OR from clipboard
So use $TextFile = readfile("C:\Temp\a.txt"); only here.
If you use $TextFile = "<clipboard>"; as next command you will overwrite the first command.


2.) You can switch the input (file/clipboard) by commenting out one or another.
Did you like to have this decision "on the fly" ?
By an MessageBox "Press OK for file, or cancel for clipboard"?


3.) This script works for two items only.
You want smtg like "For Each Line in $TextFile " ?
OH, and there is no prediction if an line holds an local or an web URL, right?

.

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

Re: Script Request - File Selector

Post by SkyFrontier »

@Stefan:
1) Yeah, I tested one OR another. Post both for a matter of being concise.
2) A message box would be nice (if it bothers me in real usage, I guess I can disable it easier than enabling it from a non-message box script).
3) Yes, ideally this must work for any number of files' addresses, no matter what input their nature is: URLs or local paths, mixed up or not.
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...

Post Reply