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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the filename after copied. 1

Status
Not open for further replies.

eyeshield21

Programmer
Aug 13, 2014
62
PH

i use this to copy a file to specific folder:
Code:
source=GETFILE()
source = "'" + source + "'"
targetdir="C:\System\ORD"

targetdir = "'" + targetdir + "'" && Add ' so that the complete path is treated as one string
copy file &source to &targetdir
what i want is to get the complete location of the copied file including its filename.
 
Use Justfname()
lcdest = addbs(m.targetdir) + justfname(m.source)

It's better to use name expression instead of macrosubstitution, and "mdot"
copy file (m.source) to (m.targetdir)

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Hi

I think the target file would be called:


Code:
m.TargetFile = targetdir+"\"+justfname(source)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
by the way, how to replace the spaces on filename into dot.
 
Use filename = Chrtran(m.filename,space(1),'.')
But copy file (m.source) to (m.targetdir) support spaces in filenames

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Yes, there is no need to replace spaces by dots for commands to work with name expressions. There also is no need to add extra string delimiters, that only is needed when using macro substitution like was done.

But there might be a need to visualize spaces. The typical solution would use underscores instead of spaces, though, like VFP does it you eg USE "some table.dbf" - its alias becomes some_table. A plus is a valid replacement of spaces in URL encoding or %20, as 0x20 = ASC(" ") = 32. %xx can be used to encode any ASCII char from 00 to ff or 0 to 255. You could even encode allowed chars like letter with the general %xx encoding, eg %41 for large letter A. Obviously that renders names unreadable.

Dots are fine, though, unless you would have the unusual case of a file extension including a space, but that never happened to me. Obviously replacing the space in there would render the file to have a different file extension, but that's also true for any other replacement and is a corner case anyway.

Bye, Olaf.
 
One thing, should you not be checking that the file isn't already there before copying it?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Seems to me that ForcePath() might be useful here:

Code:
lcdest = FORCEPATH(m.source, m.targetdir)

Tamar
 
Griff has a good point.

If you asked because you think the file could end up with ~2 or (2) appended, if the file name already existed, you don't know vfp COPY overwrites files, the target file will have 1:1 the source file name, unless perhaps some unicode is involved. And that is an extra concern, but quite untypical.

You get a safety question, if you SET SAFETY ON. If it's OFF think a bit before turning it on. In general safety is a good concept of course, but SAFETY ON causes lots of security questions also when handing tags, zapping a table or cursor etc. The good developer knows when to temporarily set safety off and take caution to eg not zap any important data, but especially the typical user response to not allow deletion/overwriting can also be a bad choice, eg keeping an outdated file and prevent a new backup, a reindex etc.

Bye, Olaf.
 
yes and im trying it now..it is just the use of if then else..right?
 
Well, depends what you decide to do. You can SET SAFETY OFF, then COPY, then SET SAFETY ON again to copy in any case, you can check via checking NOT FILE(targetfilename) or ADIR(laDummy,targetfilename)=0, if the target file does not exist and only then copy or add something to the file name to create a non existant file name in every case. Always adding a prefix or suffix like lctargetfilename=lctargetfilename+sys(2015) you get a unique filename and won't need to check.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top