Script to move files

Discuss and share scripts and script files...
Post Reply
Thom_the_printer
Posts: 3
Joined: 01 Nov 2020 12:44

Script to move files

Post by Thom_the_printer »

My apologies up front if this has been answered somewhere else in the archives. I spent the better part of yesterday searching for something simple but honestly didn't have much success.

I would like to have a script that I can manipulate (hopefully easily) by changing simple variables.

What I need to have happen is moving files from "C:\dir_1\sub_1\*.pdf" to another directory for processing. I've been using RoboTask in the past due to it's ease of use. However....if you need to move (MOVE or COPY) a few thousand files, it takes a fair amount of time.

This being said, is there also a library of videos that perhaps show someone how to best program the script features?

I'll appreciate any help and I thank you in advance for taking the time to read this post.

Thom

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

Re: Script to move files

Post by highend »

Code: Select all

    $src = "C:\dir_1\sub_1";
    $ext = "*.pdf"; // Multiple ones can be appended (separator is ";")
    $dst = "R:\dst";

    moveto $dst, quicksearch("$ext /n", $src, "|"), , 2, 2, 1;
One of my scripts helped you out? Please donate via Paypal

Thom_the_printer
Posts: 3
Joined: 01 Nov 2020 12:44

Re: Script to move files

Post by Thom_the_printer »

Thank you Highend for your response. I've come across quite a few of your posts and some have been very interesting that I've bookmarked for later.

I do have a question however. Can you please explain what the following means:

....

moveto $dst, quicksearch("$ext /n", $src, "|"), , 2, 2, 1;

What does the above line actually mean please?

Thank you!

Thom!

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

Re: Script to move files

Post by highend »

It moves the files it finds in the source folder into the destination folder.

It would automagically create the destination folder if it doesn't exist yet
It doesn't recreate the source path structure in the destination folder
It overwrites older files in destination
One of my scripts helped you out? Please donate via Paypal

Thom_the_printer
Posts: 3
Joined: 01 Nov 2020 12:44

Re: Script to move files

Post by Thom_the_printer »

Highend,

First let me thank you again for your help on this. I tested this with about 3,500 files and it was mere seconds to process and move. That's awesome!

I wanted to know if there is something built into XY that will act as a "script manager" of sorts? I wanted to know if there was a way to possibly nest scripts to run in secession. Sometimes I may need to run scripts 1 & 4 or 2 & 7 but there may be times when I need to run 1 through 7 automatically.

Does XY have something built in to manage these? If so, please let me know where I can read up on this.

Almost forgot, does XY work with hot folders or watched folders?

Thank you,

Thom

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

Re: Script to move files

Post by highend »

No, there is no inbuilt script manager.
hot folders or watched folders?
What exactly are hot folders or watched folders?
One of my scripts helped you out? Please donate via Paypal

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

Re: Script to move files

Post by highend »

Btw, a minimal script starter would look like this but
a.) There is no automation
b.) If a script requires a previous script to be executed completely before being started you would need to implement that in all those scripts and in the starter (e.g. through a common shared permanent variable)

Code: Select all

    // Load script(s) and wait for them to return before running the next one
    // Each script that is expected to work with this launcher script requires
    // this additional code:
    /*
        // At the beginning of the script (1 = Script is running)
        perm $P_SCRIPT_STATE = 1;

        // The script part itself...
        // If the script fails for some reason, set the error code with e.g.:
        // $P_SCRIPT_STATE = -3;
        // This value must be <= -1 and can be evaluated by the launcher script
        // If you don't set $P_SCRIPT_STATE at such a point and the script
        // never reaches it end because of this, the launcher script would run
        // forever (or better: until you stop it by pressing the escape key)!

        // At the end: Set return value to 0 (= success)
        $P_SCRIPT_STATE = 0;
    */

    // We setup a permanent variable here that allows the launcher script
    // to determine if a script has finished or failed
    // It cannot track the state of the last / final script to be executed!
    // This initial value MUST be set to 0 at this point!
    perm $P_SCRIPT_STATE = 0;

    // Disable status bar updates
    showstatus 0;

    $scripts = inputselect("Select script(s)...", listfolder(<xyscripts>, "*.xys", 1, <crlf>), <crlf>, 1+2+32+16+2048+16384, , 600, 800);
    if ($scripts) {
        $cnt = gettoken($scripts, "count", <crlf>);
        $i = 0;
        while (true) {
            // A script returned an error
            if ($P_SCRIPT_STATE <= -1) {
                status "Script " . quote(gpc(gettoken($scripts, $i, <crlf>), "file")) . " failed with return code $P_SCRIPT_STATE", "8B4513", "alert";
                break;

            // A script returned successfully
            } elseif ($P_SCRIPT_STATE == 0) {
                $P_SCRIPT_STATE = 1;
                $i++;
                load gettoken($scripts, $i, <crlf>);
            }
            wait 100;
            if ($i == $cnt) { break; }
        }
    }
One of my scripts helped you out? Please donate via Paypal

Post Reply