devxlogo

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 &lcTargetFileNamelcSourceFile = "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)

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.