Script Request - Catalog Maker aka Revenge over Katrina.

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

Script Request - Catalog Maker aka Revenge over Katrina.

Post by SkyFrontier »

Is it possible via script to clone a certain folder/subfolders and files structure with zero-sized files, plus preserving original files/foders date attribs as much as possible?
This could provide almost "live images", easy to re-sync/update, serving to offline browse a computer's drive into another one, allowing for a certain level of sync'ing control I can't have with current backup/sync options provided by specialized tools with... zero impact on disk space.
Thanks in advance!
Last edited by SkyFrontier on 12 Sep 2010 02:43, edited 1 time in total.
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 - Catalog Maker.

Post by SkyFrontier »

Oh, really...?
So give this a try... 8)

//THIS IS BETA!!! I'M NOT A SCRIPTER AND THE CODE STILL HAS SOME MINOR FLAWS!
EDIT: Put the whole code as comment - so you'll really won't harm yourself if you don't know what exactly you're doing. Just in case...
See next post for an updated version!
***You can use ESC to abort its execution at anytime (ah, IF ONLY I had it in my veins when this thing ate some files, inadvertently... :| ).***

Code: Select all

/*
"Catalog Maker v 0.9 - Code by TheQwerty, Stefan and Jacky, re-sampled by SkyFrontier"
  #263; //show all items in branch
  sel f; //selects all files, no folders
  end(getinfo("CountSelected") < 1), "Please select some files first.";
  ////get name, creation date and modification date from selected files:
  $Records = report("{Name}, {Created}, {Modified}<crlf>",1);
  $Records = "{Name}, {Created}, {Modified}<crlf>" . $Records;
  ////write to an file "__timestamps" into current folder:
  writefile("<xydata>\_RES\Temp\__timestamps", $Records);
  ////cosmetics:
  status "Get timestamps is done.";

   sel f; End GetInfo("CountSelected") < 1, "No item(s) selected.";
   Global $files;
   $files = Report("{Dir |{FullName};{Ext}<crlf>|}", 1);
   Setting "AllowRecursion", 1;
   Sub "_ZERO";
   $files = RegexReplace($files, "^(.*);.*<crlf>", "$1|");
   Delete 1,1,$files;
   sel f; //selects all files, no folders.
   rename s, "-01/";

  sel f;
  ////load info from an file "__timestamps" in current folder:
  $Records = readfile("<xydata>\_RES\Temp\__timestamps");

  ////For Each Item in Itemlist $Records DO:
  $LOOP=2;
  while(1)
  {
    ////Get next record set:
    $RecSet = gettoken($Records, $LOOP, "<crlf>");
    if ($RecSet==""){break;}

    ////split the record into parts and get
    ////the file name (and add the current path):
    $file = "<curpath>\" . gettoken($RecSet, 1, ",");

    ////the creation date:
    $cDate = gettoken($RecSet, 2, ",");
      ////set the creation date to $file:
      timestamp c, "$cDate", "$file";

    ////the modification date:
    $mDate = gettoken($RecSet, 3, ",");
      ////set the modification date to $file:
      timestamp m, "$mDate", "$file";

  incr $LOOP;
  }
  ////cosmetics:
  status "Set timestamps is done.";
  while($loop<3){beep; beep 1000, 200;beep 1200, 400;incr $loop;wait 500;}

"_ZERO"
   Global $files, $i;
   $i = $i Like "" ? 1 : $i;
   $token = GetToken($files, $i, "<crlf>");
   End $token Like "",, 1;
   $file = GetToken($token, 1, ";");
   $ext = GetToken($token, 2, ";");
   $newFile = RegexReplace($file, "$ext$", "$ext");
   New $newFile;
   $i = $i + 1;
   Sub "_ZERO";
*/
As you can see, it's a pure code stealing out of Grab Date Info and Set as Name (v1.0, Stefan's code) and a kind of a index builder coded by TheQwerty and revised by Jacky.
Reading some scripts I've learned that "Show All Items in Branch" can sort of emulate recursive search, allowing to deal with files sorted in subfolders.
Also, the "sel f" (select files only) has a major role in dealing with what will be touched by the script.
-can someone please clean out the code, if necessary?
-Stefan, what's the function of the "while($loop<3){beep; beep 1000, 200;beep 1200, 400;incr $loop;wait 500;}" part of the code? I can't hear any beeping at the end because...
-scripts halts at some point throwing a message error:

Code: Select all

XYplorer - Timestamping failed. The selected item(s) might be opened and locked by another application.
This happens when it tries to rename files under subfolders (eliminating the "-01" prefix, necessary to avoid names collision at the initial steps). Also, the modification date is not matching original dates. Why this happens? Anyone able to provide a fix, please?
-can someone please provide a confirmation box telling that "x" files will be zeroed, asking to cancel or continue?
Thank you!
Last edited by SkyFrontier on 13 Sep 2010 00:56, edited 3 times in total.
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 - Catalog Maker.

Post by SkyFrontier »

STILL BETA! But THIS VERSION WORKS! (except if you have a large number of folders/files to deal with... :( See below for more info.)
*WARNING* - read the original topic. THIS WILL ERASE THE ENTIRE FOLDER WHERE IT'S LAUNCHED FROM, PLUS SUBFOLDERS! BE WARNED!

EDIT: Put the whole code as comment - so you'll really won't want to blame me if things doesn't happen the way you expected. BE SURE on WHAT YOU DO WITH THIS LITTLE DEVIL!
_______________________TAKE CARE!!!_______________________
________________________ :twisted: 666 :twisted:________________________
(and try not to harm any ex-girlfriend or roommate, too... lol)
***You can use ESC to abort its execution at anytime (ah, IF ONLY I had it in my veins when this thing ate some files, inadvertently... :| ).***

Code: Select all

/*
"Catalog Maker v 1.0 - Code by TheQwerty, Stefan and Jacky; re-sampled by SkyFrontier"
  #263; //show all items in branch
  #485; //refresh file list
  sel f; //selects all files, no folders
  #485; //refresh file list
  end(getinfo("CountSelected") < 1), "Please select some files first.";
  ////get name, creation date and modification date from selected files:
  $Records = report("{Fullname}, {Created}, {Modified}<crlf>",1);
  $Records = "{Fullname}, {Created}, {Modified}<crlf>" . $Records;
  ////write to an file "__timestamps" into current folder:
  writefile("<xydata>\_RES\Temp\__timestamps", $Records);
  ////cosmetics:
  //status "Get timestamps is done.";

   sel f; End GetInfo("CountSelected") < 1, "No item(s) selected.";
   Global $files;
   $files = Report("{Dir |{FullName};{Ext}<crlf>|}", 1);
   Setting "AllowRecursion", 1;
   Sub "_ZERO";
   $files = RegexReplace($files, "^(.*);.*<crlf>", "$1|");
   Delete 1,1,$files;
   focus l;
   #485; //refresh file list
   sel f; //selects all files, no folders.
   rename s, "-01/";

  sel f;
  ////load info from an file "__timestamps" in current folder:
  $Records = readfile("<xydata>\_RES\Temp\__timestamps");

  ////For Each Item in Itemlist $Records DO:
  $LOOP=2;
  while(1)
  {
    ////Get next record set:
    $RecSet = gettoken($Records, $LOOP, "<crlf>");
    if ($RecSet==""){break;}

    ////split the record into parts and get
    ////the file name (and add the current path):
    $file = gettoken($RecSet, 1, ",");

    ////the creation date:
    $cDate = gettoken($RecSet, 2, ",");
      ////set the creation date to $file:
      timestamp c, "$cDate", "$file";

    ////the modification date:
    $mDate = gettoken($RecSet, 3, ",");
      ////set the modification date to $file:
      timestamp m, "$mDate", "$file";

  incr $LOOP;
  }
  ////cosmetics:
  status "Set timestamps is done. Catalog created!";
  //while($loop<3){beep; beep 1000, 200;beep 1200, 400;incr $loop;wait 500;}

"_ZERO"
   Global $files, $i;
   $i = $i Like "" ? 1 : $i;
   $token = GetToken($files, $i, "<crlf>");
   End $token Like "",, 1;
   $file = GetToken($token, 1, ";");
   $ext = GetToken($token, 2, ";");
   $newFile = RegexReplace($file, "$ext$", "$ext");
   New $newFile;
   $i = $i + 1;
   Sub "_ZERO";
*/

Code: Select all

Notes:

"Catalog Maker v 1.0 - Code by TheQwerty, Stefan and Jacky, re-sampled by SkyFrontier"
          #263; //show all items in branch
Bloat?  #485; //refresh file list
Bloat?  sel f; //selects all files, no folders
Bloat?  #485; //refresh file list
------
New:     $Records = report("{Fullname}, {Created}, {Modified}<crlf>",1);
            $Records = "{Fullname}, {Created}, {Modified}<crlf>" . $Records;

Previous:   $Records = report("{Name}, {Created}, {Modified}<crlf>",1);
               $Records = "{Name}, {Created}, {Modified}<crlf>" . $Records;
effect: was not allowing recursive work.
------
New:        Delete 1,1,$files;
               focus l;
               #485; //refresh file list
               sel f; //selects all files, no folders.

Previous:   Delete 1,1,$files;
               sel f; //selects all files, no folders.

effect: allows selection of ALL files in list for renaming
------
New:             $file = gettoken($RecSet, 1, ",");
Previous:        $file = "<curpath>\" . gettoken($RecSet, 1, ",");

effect: avoids conflict with required report(Fullname) info, above.
Yet to confirm:

-can someone please clean out the code, if necessary?
-Stefan, what's the function of the "while($loop<3){beep; beep 1000, 200;beep 1200, 400;incr $loop;wait 500;}" part of the code? -"while" stands for telling the script to repeat the beeping, only?
-can someone please provide a confirmation box telling that "x" files will be zeroed, asking to cancel or continue?
-wasn't supposed that writefile("<xydata>\_RES\Temp\__timestamps" could create the folder in case of it being non-existent? Or at least ask for its creation? It works that way in some cases, but not in others, and could happen when entering a (non-existent) path directly (CTRL+C) into address bar plus pressing enter.
Thank you!

Tag - xyScript
Last edited by SkyFrontier on 27 Sep 2010 22:27, edited 1 time in total.
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 - Catalog Maker aka Revenge over Katrina.

Post by SkyFrontier »

Significant problem:
Folder to be cataloged has 2596 files, 105 folders.
When executing the script, XY crashes and shuts down in a XP SP3 machine, and freezes asking to close program in a Vista 7 Basic rig. It throws an "out of stack space" message at the W7 (see sShot).
Total of files out of the interrupted script execution: 3047 (being the difference the result of the ceased duplication of the folders' contents).
It seems somewhat related to what Mesh described here, workaround'ed by Muroph's script.
-any ideas on how to solve/circumvent this?
Thanks!
Attachments
ERR_OutOfStackSpace_LoRes.jpg
ERR_OutOfStackSpace_LoRes.jpg (52.42 KiB) Viewed 6514 times
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...

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by nas8e9 »

SkyFrontier wrote:Significant problem:
Folder to be cataloged has 2596 files, 105 folders.
When executing the script, XY crashes and shuts down in a XP SP3 machine, and freezes asking to close program in a Vista 7 Basic rig. It throws an "out of stack space" message at the W7 (see sShot).
Total of files out of the interrupted script execution: 3047 (being the difference the result of the ceased duplication of the folders' contents).
It seems somewhat related to what Mesh described here, workaround'ed by Muroph's script.
-any ideas on how to solve/circumvent this?
Thanks!
I can't offer specific help but could you try to confirm with the latest beta (currently 9.50.0108)? In general, it helps troubleshooting.

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

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by SkyFrontier »

nas8e9:
I can't offer specific help but could you try to confirm with the latest beta (currently 9.50.0108)? In general, it helps troubleshooting.
Updated XY (.50 - .0108) at the winXP machine - same problem. :?
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...

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

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by admin »

SkyFrontier wrote:nas8e9:
I can't offer specific help but could you try to confirm with the latest beta (currently 9.50.0108)? In general, it helps troubleshooting.
Updated XY (.50 - .0108) at the winXP machine - same problem. :?
Thank you!
Looks like your script has an endless recursion. Your bug. :P

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

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by SkyFrontier »

admin:
Looks like your script has an endless recursion. Your bug. :P
Well.
:roll:
That's what I was able to do - FrankenScript! :P
(here we go again and add another warning to the minefield... lol)
-that means the script is now officially bull$11.L Sorry, guys, I did my best... :cry:
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...

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by TheQwerty »

If the user specifies a source of "D:\Source".
And then they select a destination of "C:\Katrina".
Should ghosted contents be in: "C:\Katrina" or "C:\Katrina\Source"?

In other words should it also ghost the source folder or just its contents?

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

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by SkyFrontier »

@TheQwerty:
The problem previously discussed regarding dir creation applies to the section:

Code: Select all

writefile("<xydata>\_RES\Temp\__timestamps", $Records);
-if there is no such target directory previously created, script won't work.
There's also the endless recursion problem pointed by Don that completely kills the script when dealing with large directories (too bad for a Catalog Maker, huh? :wink: ), described above.
The code works (and it's aimed to do that) on any directory - select the folder, start script, then you'll have all files in there erased but having their timestamps preserved. OF COURSE this must be used at a cloned folder (unless one really wants to delete source files!). Ideally the script should be able to clone (tree structure + zero-size files + original timestamps) a folder structure on another target location, but that's the only way I could come up with.
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...

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by TheQwerty »

I'm ignoring your frankenscript and starting fresh... :P

So which way do you want it, does it also ghost the selected directory or just its contents?

For example:
If the selected source is: "D:\Source" and its contents is:
D:\Source\a.txt
D:\Source\b.txt
D:\Source\c.txt

And the selected destination is "C:\Katrina" which of the following should be the result:
1)
C:\Katrina\a.txt
C:\Katrina\b.txt
C:\Katrina\c.txt

2)
C:\Katrina\Source\
C:\Katrina\Source\a.txt
C:\Katrina\Source\b.txt
C:\Katrina\Source\c.txt

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

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by SkyFrontier »

2)
C:\Katrina\Source\
C:\Katrina\Source\a.txt
C:\Katrina\Source\b.txt
C:\Katrina\Source\c.txt

-this will allow total control over cloned contents, so I can just grab the entire "source" folder and backup it (zero-sized files = seconds!) anywhere I need at any time (I have to sync/control stuff via such method on at least 2 computers; 3, when all works as intended).
Thanks for the fresh start! (=less chances to find another bug on a critical task, as I had when found the recursion problem last time!)
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...

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by TheQwerty »

I didn't abandon ship...

Please try this and let me know if it does what you want correctly.
NOTE: This script MUST be saved to a file and then executed using one of the various Load methods.

Code: Select all

/******************************************************************************
**	Ghost.xys
**
**	This script has two main functions:
**	1) Generate a listing of all items in a branch recursively.
**		This contains just the type, relative path\name, and the item dates.
**		It is in no way intended to compete with XY's Report feature.
**	2) Ghost all items in a branch to another location.
**		Ghosting means to clone the structure of a branch with zero-sized files
**		while retaining the item's Created, Modified, and Accessed dates.
**
**	After either function the script can display a summary of all items, and
**	in the latter case whether they could be ghosted or not, or prompt to save
**	the summary to a file.
**
**	Notes:
**		-When saving to an existing file the summary will be appended.
**		-The summary is tab delimited, and looks best with a monospaced font.
**			While not ideal for the displays possible via XY scripting, these
**			decisions make using this data in Excel or other apps easier.
**
**	Author: TheQwerty
**	Profile: http://www.xyplorer.com/xyfc/memberlist.php?mode=viewprofile&u=438
**	Forum Topic: http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=5408
******************************************************************************/
Ghost.xys
(16.43 KiB) Downloaded 252 times
Last edited by TheQwerty on 05 Oct 2010 21:37, edited 1 time in total.

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

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by SkyFrontier »

Code: Select all

Script Version not found!
This script can no longer trust itself and/or XYplorer's scripting engine.
Execution aborted.
Trying to get around...
-thanks!

-tried to run the script from "Run Script..."; trying to run it from <xyscripts>.
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...

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script Request - Catalog Maker aka Revenge over Katrina.

Post by TheQwerty »

It MUST be saved to a file and then executed using one of the Load methods.

Post Reply