nisus.com
https://www.nisus.com/forum/

Help with choose file macro
https://www.nisus.com/forum/viewtopic.php?f=17&t=3408
Page 1 of 1

Author:  loulesko [ 2009-05-28 09:06:41 ]
Post subject:  Help with choose file macro

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

Author:  martin [ 2009-05-28 11:42:31 ]
Post subject:  Re: Help with choose file macro

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.

Author:  Kino [ 2009-05-29 07:18:29 ]
Post subject:  Re: Help with choose file macro

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.

Author:  loulesko [ 2009-06-01 02:59:37 ]
Post subject:  Re: Help with choose file macro

Thank you both. That helped a lot.

Lou

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/