Help with choose file macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
loulesko
Posts: 89
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Help with choose file macro

Post by loulesko » 2009-05-28 09:06:41

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/'

User avatar
martin
Official Nisus Person
Posts: 4278
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Help with choose file macro

Post by martin » 2009-05-28 11:42:31

Hi Lou, the problem is this line:

Code: Select all

$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: Select all

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

Code: Select all

$file = Choose File "$path", 'Move'
Hope that helps.

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Help with choose file macro

Post by Kino » 2009-05-29 07:18:29

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: Select all

File.moveFromPathToPath '~/Documents/Nisus Documents/MyLife.rtf' '~/Documents/Writing/TrashFolder/MyLife.rtf' 

So your macro will be something like this:

Code: Select all

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

User avatar
loulesko
Posts: 89
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: Help with choose file macro

Post by loulesko » 2009-06-01 02:59:37

Thank you both. That helped a lot.

Lou

Post Reply