Script to move and prefix files based on date

Discuss and share scripts and script files...
Post Reply
rclkrtrzckr
Posts: 65
Joined: 03 Jan 2017 13:10
Location: Zurich, Switzerland

Script to move and prefix files based on date

Post 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

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

Re: Script to move and prefix files based on date

Post 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)!
One of my scripts helped you out? Please donate via Paypal

rclkrtrzckr
Posts: 65
Joined: 03 Jan 2017 13:10
Location: Zurich, Switzerland

Re: Script to move and prefix files based on date

Post by rclkrtrzckr »

:shock:

Wow! Thanks!

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

Cheers

Rico

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

Re: Script to move and prefix files based on date

Post by highend »

It's a b(atch) rename operation
One of my scripts helped you out? Please donate via Paypal

rclkrtrzckr
Posts: 65
Joined: 03 Jan 2017 13:10
Location: Zurich, Switzerland

Re: Script to move and prefix files based on date

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

rclkrtrzckr
Posts: 65
Joined: 03 Jan 2017 13:10
Location: Zurich, Switzerland

Re: Script to move and prefix files based on date

Post 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;
 }
 

Post Reply