Reply to topic  [ 4 posts ] 
Help with choose file macro 
Author Message
User avatar

Joined: 2008-01-20 11:08:35
Posts: 89
Location: California
I'm trying to get the code below to work, I keep getting an error saying that $file doesn't exists. I know it's simple, but if I could get a quikc example it would set me in the right direction to make more file moving macros that I need.

many thanks
Lou


$path = "~/Documents/Nisus Documents/"
$file = Choose File '$path', 'Move'
File.moveFromPathToPath '$file', ‘~/Documents/Writing/TrashFolder/'


2009-05-28 09:06:41
Profile WWW
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Hi Lou, the problem is this line:
Code:
$file = Choose File '$path', 'Move'

When you use single quote marks for a string/text, no variable interpolation occurs (replacing variable names with their content). Since $path is already a string, I'd recommend:
Code:
$file = Choose File $path, 'Move'

But you could also use:
Code:
$file = Choose File "$path", 'Move'

Hope that helps.


2009-05-28 11:42:31
Profile WWW

Joined: 2008-05-17 04:02:32
Posts: 400
You have to remove single quotes from '$file' in the last command too. Also there seems to be a misunderstanding. File.moveFromPathToPath requires a file path as the second argument. For example, if you want to move “MyLife.rtf”, the command will be...
Code:
File.moveFromPathToPath '~/Documents/Nisus Documents/MyLife.rtf' '~/Documents/Writing/TrashFolder/MyLife.rtf'

So your macro will be something like this:
Code:
$path = '~/Documents/Nisus Documents/'
   # The path is enclosed between single quotes because it does not contain a variable.
$file = Choose File $path, 'Move'
$fileName = $file.lastFilePathComponent
File.moveFromPathToPath $file, "~/Documents/Writing/TrashFolder/$fileName" 
   # The path is enclosed between double quotes because it contains a variable ($fileName).

Edit:
• Perhaps it will be a nice enhancement if File.moveFromPathToPath works as you expected, i.e. move a file to a folder if the second argument is not a file path but an existing folder path.
• Corrected my English and added comments to the macro.


2009-05-29 07:18:29
Profile
User avatar

Joined: 2008-01-20 11:08:35
Posts: 89
Location: California
Thank you both. That helped a lot.

Lou


2009-06-01 02:59:37
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software