You could do this in two ways:
Just use &&folderpath
in the spool commands directly, e.g.:
set spool on;
set sqlformat csv;
spool &&folderpath/mycsvfile1.csv
select * from i_pty;
spool off;
spool &&folderpath/mycsvfile2.csv
select * from i_leg;
spool off;
Or use DEFINE to assign the value (which you'd then have to reference in the same way as the previous answer, so you don't gain anything, really...):
set spool on;
set sqlformat csv;
define fpath = &folderpath
spool &&fpath/mycsvfile1.csv
select * from i_pty;
spool off;
spool &&fpath/mycsvfile2.csv
select * from i_leg;
spool off;
Using the double ampersand stops Oracle from prompting you for a value each time you reference the same substitution variable. If you want your next script or next run through of this script to be prompted again for the value of folderpath, then you will need to include undefine folderpath
(and maybe undefine fpath
) at the end of the script.
Also, you may want to include set verify off
at the top of your script.
N.B. you were using @ in your spool file name - that has no place there. It's only used when you're running a script.