dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual FoxPro
Expertise: Beginner
Nov 9, 1999

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Copying/Renaming Files

Question:
How do I use a memory variable as a filename when copying and renaming a file?

Answer:
For sake of example, let's say that you have a character variable called lcSourceFileName that contains the name of the file to copy, and a character variable called lcTargetFileName that contains the name of the file to copy to.

Either of the following two pieces of code will work:

 
lcSourceFile = "D:\ABC.TXT"
lcTargetFile  = "D:\XYZ.TXT"
COPY FILE &lcSourceFileName TO &lcTargetFileName

lcSourceFile = "D:\ABC.TXT"
lcTargetFile  = "D:\XYZ.TXT"
COPY FILE (lcSourceFileName) TO (lcTargetFileName)
I prefer the second example because it is easier to extend than first; any FoxPro expression can get put between the parentheses:
 
lcSourcePath = "D:\"
lcSourceFile = "ABC.TXT"
lcTargetFile  = "D:\"
lcTargetFile  = "XYZ.TXT"
COPY FILE (lcSourcePath+lcSourceFileName) TO (lcTargetPath+lcTargetFileName)
If you had two functions, GetSourcePath() and GetTargetPath(), you could execute the following:
COPY FILE (GetSourcePath()+lcSourceFileName) TO (GetTargetPath()+lcTargetFileName)
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date