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/'
Help with choose file macro
- martin
- Official Nisus Person
- Posts: 5228
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Help with choose file macro
Hi Lou, the problem is this line:
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:
But you could also use:
Hope that helps.
Code: Select all
$file = Choose File '$path', 'Move'
Code: Select all
$file = Choose File $path, 'Move'
Code: Select all
$file = Choose File "$path", 'Move'
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...
So your macro will be something like this:
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.
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).
• 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.
Re: Help with choose file macro
Thank you both. That helped a lot.
Lou
Lou