I need help with this script

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

I need help with this script

Post by timle » Mon Sep 17, 2007 8:57 pm

Let>PuzzleCode=pr
Let>directory=c:\test

GetFileList>%directory%\*.*,files
Separate>files,;,oldname

MidStr>%oldname%,3,8,value1
MidStr>%oldname%,3,2,value2
MidStr>%oldname%,6,2,value3
Let>newname=%PuzzleCode%%value1%%PuzzleCode%%value2%%value3%puzzle.eps

CopyFile>oldname,newname
Last edited by timle on Thu Sep 20, 2007 6:15 pm, edited 1 time in total.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Sep 17, 2007 9:07 pm

Separate creates an array. Your example splits the list "files" into array "oldname". So you end up with oldname_1, oldname_2 .... oldname_count

So youre MidStr commands won't work. oldname is not a variable. I expect you actually intend to operate on each element of the array inside a loop?

Something like:

Code: Select all

Let>PuzzleCode=pr
Let>directory=c:\test

GetFileList>%directory%\*.*,files
Separate>files,;,oldname

Let>k=1
Repeat>k
  Let>thisfile=oldname_%k%
  MidStr>%thisfile%,3,8,value1
  MidStr>%thisfile%,3,2,value2
  MidStr>%thisfile%,6,2,value3 
  Let>newname=%PuzzleCode%%value1%%PuzzleCode%%value2%%value3%puzzle.eps
  CopyFile>oldname,newname
  Let>k=k+1
Until>k>oldname_count
But I'm guessing because I'm not really sure what you are trying to do ...
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Script seems to do nothing ..help

Post by timle » Tue Sep 18, 2007 5:35 pm

The script did not do any thing.
I would like to change the old name to the new name, but it did not work

I must have over look something...

====================================
//objective
//file name is: cm09_16___cmNYTpuz
//need to change to: pr09_16___pr0916puzzle


Let>PuzzleCode=pr
Let>directory=c:\comictest

GetFileList>%directory\%*.*,files
Separate>files,;,oldname

Let>k=1
Repeat>k
Let>thisfile=oldname_%k%
MidStr>%thisfile%,3,8,value1
MidStr>%thisfile%,3,2,value2
MidStr>%thisfile%,6,2,value3
Let>newname=%PuzzleCode%%value1%%PuzzleCode%%value2%%value3%puzzle.eps
CopyFile>oldname,newname
Let>k=k+1
Until>k>oldname_count

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Sep 18, 2007 6:06 pm

I didn't test the rename part but the reason it won't do anything is that you have a typo in this line:

GetFileList>%directory\%*.*,files

should be this:

GetFileList>%directory%\*.*,files

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Sep 18, 2007 6:09 pm

Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

debugging is cool

Post by timle » Tue Sep 18, 2007 7:31 pm

the debug helps alot!!!

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

some thing missing

Post by timle » Tue Sep 18, 2007 8:19 pm

I got the script working, but it did not process all files in the directory. If I have 3 files in the directory, it only process 2

thanks


Let>PuzzleCode=pr

GetFileList>c:\comictest\*.*,files
Separate>files,;,oldname


Let>k=0
Repeat>k
Let>thisfile=oldname_%k%
MidStr>%thisfile%,16,2,value1
MidStr>%thisfile%,19,2,value2
Let>newname=%PuzzleCode%%value1%_%value2%___%PuzzleCode%%value1%%value2%puzzle.eps
CopyFile>%thisfile%,c:\comictest\%newname%
Let>k=k+1
Until>k,oldname_count

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Sep 18, 2007 8:22 pm

Change your Until line to:

Until>k>oldname_count

...

Or initialise k to 0 and increment at the start of the loop instead of the end.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

works great

Post by timle » Tue Sep 18, 2007 8:39 pm

thank you

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts