Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Substitution 2

Status
Not open for further replies.

harryjr

Programmer
Jan 4, 2001
27
US
How do I use macro substitution in the COPY FILE command.

I want to copy a TEMPLATE.XLS file to one named the CURRENT DATE.

lcflnm = DTOC(DATE())+".XLS"

COPY FILE template.xls TO &lcflnm (does not work)
COPY FILE template.xls TO (lcflnm) (does not work)

Can anyone resolve this?

Thanks,

Harry
 
DTOC(DATE()) will return a character string with slashes ("/") in the string, which of course, Windows interprets as part of a directory tree.
Try using DTOS(DATE()) instead, as in
Code:
lcflnm = DTOS(DATE())+".XLS"
COPY FILE template.xls TO (lcflnm) should then work.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Are the "/" in the lcFLNM really needed. That is what is messing you up.

It is trying to create a directory called 12/09/2009.XLS.

try replacing the "/" with "-". that will work.
Code:
lcflnm = STRTRAN( DTOC(DATE())+".XLS","/","-")

Josh
 
I'd rather prefer the date format independant function DTOS, you can make this more readable by inserting whatever seperator character. DTOC() is very specific to whatever date format is configured and so the same code does produce different results, eg if the sysformat is set to points as in the german date format, then you'd not get slashes, you'd get a valid file name, but it would then differ from the goal to have eg minus as the seperator.

Use Transform(Dtos(Date()),"@R 9999-99-99"), that'll always produce the same output format.

Bye, Olaf.
 
Both DTOC() and TTOC() support a second parameter that formats the output in a consistent indexable format:

Code:
  lcToday = DTOC(DATE(),1) && YYYYMMDD
  lcNow   = TTOC(DATE(),1) && YYYYMMDDhhmmss

 
True brigmar,

and I know that. And DTOS() is shorter for DTOC(DATE(),1), it produces the same format, so I prefer DTOS() for simplicity.

There is no replacement for TTOC(DateTime(),1) though, but that is not needed here.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top