clone file sctructure here

Features wanted...
tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: clone file sctructure here

Post by tiago »

in another post I wrote on specific features a program has over concurrency.
I really, badly needed this feature last December and hands down no other software in the known universe can do this. So I ask forum colleagues: any alternative you may know?
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: clone file sctructure here

Post by tiago »

i was given this code which does pretty much exactly what i need.
skyfrontier mentioned on it being slow and it really, $really$ is. Tried to make it run faster but analyzing it gives me no hint on how. Adding accessed dates as suggested will probably make it slower.
any hints anyone?

Code: Select all

//toDo: add accessed dates?

//started 17:47, ended 18:04, on 568 files/5896 folders - painfully slow

    $catalogName = "_CATALOG\"; // always use the "\" as in "_CATALOG\"

   $workingPath = InputFolder("<curpath>", 'Select the Source folder:');
   $dest = InputFolder("<curpath>", 'Select the Destination folder:');

    $basePath = "$workingPath\";
    sel; // remove any selection so messages can be seen...
    $items = folderreport("itemsrel", "r", "$workingPath", "r", , "|");
    status "Please wait, this WILL take time if you are seeing this...";
        foreach ($item, $items, "|") {

   $source = report("{Name}", "$basePath$item");
   $dateCreation = report("{Created}", "$basePath$item");
   $dateModif = report("{Modified}", "$basePath$item");

   $dateModif2 = formatdate($dateModif, , "s", -2);
   $test = exists($basePath$item);
   $source = "$dest\$catalogName$item";

   IF ($test==1) { new ("$source", file); }
   ELSEIF ($test==2) { new ("$source", dir); }
   ELSEIF ($test==0) { end 1, "Item not valid or inexistent!"; }

   timestamp c, $dateCreation, $source;
   timestamp m, $dateModif2, $source;

                                   }

   beep; beep 1000, 200; beep 1500, 400;

   status "FINALLY done! - -";
Power-hungry user!!!

hermhart
Posts: 213
Joined: 13 Jan 2015 18:41

Re: clone file sctructure here

Post by hermhart »

Is it still possible to get the Paste As Zero-Byte Clone command implemented?

viewtopic.php?p=58249#p58249

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

Re: clone file sctructure here

Post by admin »

Not really. But it can be scripted, of course.

highend
Posts: 13315
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: clone file sctructure here

Post by highend »

Something like this would probably work. Highly untested so use it at your own risk

It should create a nearly perfect clone, attributes and correct file / folder times included...

Code: Select all

    // Create a zero-byte clone of the current path in the active pane inside the current path of the inactive pane
    // name|size|modified|created|accessed|attributes]
    $items = quicksearch(, , , "sm");
    end (!$items), "No item(s) in the current path, aborted!";

    $dst = gettoken(get("Tabs_sf", <crlf>, "i"), 1, <crlf>);

    showstatus 0;
    setting "BackgroundFileOps", 0;

    // Get all folder(s), remove them from the list and create them
    // Do not set the timestamps here! Creating items in them will change them anyway...
    $folders = regexmatches($items, "^(.+?\|){5}.*?D.*?(?=\r?\n|$)", <crlf>);
    if ($folders) {
        $items = regexreplace($items, "^(.+?\|){5}.*?D.*?(\r?\n|$)");
        status "Creating folder(s)...", , "progress";
        foreach($folder, $folders, <crlf>, "e") {
            // We need to remove the current path to make them relative to $dst
            $path    = gettoken($folder, 1, "|");
            $path    = replace($path, <curpath> . "\");
            $attribs = gettoken($folder, 6, "|");
            $newDst  = $dst . "\" . $path;
            if (new($newDst, "dir")) { attrstamp($attribs, 2, $newDst); }
            wait 1;
        }
    }
    // Now do all file(s)
    if ($items) {
        status "Creating file(s)...", , "progress";
        foreach($item, $items, <crlf>, "e") {
            $path     = gettoken($item, 1, "|");
            $path     = replace($path, <curpath> . "\");
            $modified = gettoken($item, 3, "|");
            $created  = gettoken($item, 4, "|");
            $accessed = gettoken($item, 5, "|");
            $attribs  = gettoken($item, 6, "|");
            $newDst   = $dst . "\" . $path;
            if (new($newDst, "file")) {
                attrstamp($attribs, 2, $newDst);
                timestamp "c", $created,  $newDst;
                timestamp "m", $modified, $newDst;
                timestamp "a", $accessed, $newDst;
            }
            wait 1;
        }
    }

    // Finally set timestamps for the folder(s)
    if ($folders) {
        // Reverse them to be able to do the deeper paths first
        $folders = formatlist($folders, "v", <crlf>);
        status "Timestamping folder(s)...", , "progress";
        foreach($folder, $folders, <crlf>, "e") {
            $path     = gettoken($folder, 1, "|");
            $path     = replace($path, <curpath> . "\");
            $modified = gettoken($folder, 3, "|");
            $created  = gettoken($folder, 4, "|");
            $accessed = gettoken($folder, 5, "|");
            $newDst   = $dst . "\" . $path;
            timestamp "c", $created,  $newDst;
            timestamp "m", $modified, $newDst;
            timestamp "a", $accessed, $newDst;
            wait 1;
        }
    }
    status "DONE...";
One of my scripts helped you out? Please donate via Paypal

hermhart
Posts: 213
Joined: 13 Jan 2015 18:41

Re: clone file sctructure here

Post by hermhart »

highend, thank you so much for posting this script!

Would it be possible to modify it so instead of it using what is in pane 1 and cloning it to pane 2, could it be where you copy the top level folder to your clipboard, then use the script to paste the structure into whatever new directory you have changed to?

After doing some testing on it, it seems to work great aside from the timestamping. I made a copy of a large structure of folders/files to test against, and If I comment out the timestamping it works flawlessly. But if I leave the timestamping in, I get errors like this, to which none of the files are open:
Error 001 (edited).jpg
Error 001 (edited).jpg (28.49 KiB) Viewed 250 times

highend
Posts: 13315
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: clone file sctructure here

Post by highend »

If a script command thinks that a file / folder is locked I can't do anything against that...
One of my scripts helped you out? Please donate via Paypal

Post Reply