Page 1 of 1

Script to move and prefix files based on date

Posted: 03 Jan 2017 13:24
by rclkrtrzckr
Hi all

I started looking into scripting today and played around with it a little. I believe there's still a lot to learn ;)

The (1st world-)problem I'd like to solve is actually pretty simple:

1. Select a bunch of files, or just one
2. Push a button
3. Move the files (skip directories!) into
$destroot
, which is something like
c:\dest\<date yyyy>\<date mm>

4. Rename the files at the same time, prefixing "
<date yyyymmdd>_
"

With my very basic skills I managed to step 3 for one file:

Code: Select all

$src="\\somewhere\inbox\1.txt";
 $destroot = "\\somewhere\<date yyyy>\<date mm>"; 
 copyto "$destroot", "$src",,3;
 goto $destroot;
I tried to attach this to a button by removing
$src
, but that didn't really work. It replicated the whole source path in the destination. As well, renaming the file didn't work.

I am pretty sure this is possible. Any hint appreciated! :)

Cheers

Rico

Re: Script to move and prefix files based on date

Posted: 03 Jan 2017 13:51
by highend
Welcome to the forum

Code: Select all

    $destroot = "\\somewhere\<date yyyy>\<date mm>";
    rename b, "<date yyyymmdd>_*", , , 8;
    moveto $destroot, ":list", , 2;
Do not forget to copy the code part correctly (each line is indented by 4 spaces)!

Re: Script to move and prefix files based on date

Posted: 03 Jan 2017 14:34
by rclkrtrzckr
:shock:

Wow! Thanks!

For the unaware: Where does the "b" on line 2 come from?

Cheers

Rico

Re: Script to move and prefix files based on date

Posted: 03 Jan 2017 14:43
by highend
It's a b(atch) rename operation

Re: Script to move and prefix files based on date

Posted: 03 Jan 2017 16:16
by rclkrtrzckr
Thanks again. One last (*cough*) question: Can I check for a selection before the ":list" gets moved?

While writing, I found this in the manual:

Code: Select all

// shows "No files selected!" if no files are selected, and skips the loop
 foreach($item, <get selecteditemspathnames>, <crlf>, , "No files selected!") {
   echo $item;
 }
I'll give it a try.

Re: Script to move and prefix files based on date

Posted: 03 Jan 2017 16:36
by rclkrtrzckr
Found it!

Thanks a ton!

Code: Select all

$count = get("CountSelected"); 
 if($count>0) {
    $destroot = "c:\somewhere\<date yyyy>\<date mm>"; 
    rename b, "<date yyyymmdd>_*", , , 8;
    moveto $destroot, ":list", , 2;
 }