varfullpathsrc: string;fullpathdest: string;begincopyfile(pchar(fullpathsrc), pchar(fullpathdest), false)end;
How about scanning the strings and duplicating every single quote you encounter. AFAIK two single quotes in a string in Pascal is interpreted as one.
fullpathdest := stringreplace(fullpathdest, ''', '''', [rfReplaceAll]);
Maybe the underlying OS call interprets an apostroph?What happens if you place quotes (") around the filename?Which OS are you using?Bart
fullpathdest := '"'+fullpathdest+'"'
fullpathdest := stringreplace(fullpathdest, '''', '''''', [rfReplaceAll]);
I guess when doing a replace you will have to do the same duplication of single quotes:Code: [Select]fullpathdest := stringreplace(fullpathdest, '''', '''''', [rfReplaceAll]);
Have you tried doing the file copy with a TFileStream? I don't know if it will work, but may be worth a try.
Procedure TSFileCopy(sourcefilename, targetfilename: String);Var S, T: TFileStream;Begin S := TFileStream.Create( sourcefilename, fmOpenRead ); try T := TFileStream.Create( targetfilename, fmOpenWrite or fmCreate ); try T.CopyFrom(S, S.Size ) ; finally T.Free; end; finally S.Free; end;End;
TSfilecopy(fullpathsrc, fullpathdest)
os=windowsplacing quotes doesnt affect anything. i used the code below to do itCode: [Select]fullpathdest := '"'+fullpathdest+'"'
Back to the original question: Windows has no problem whatsoever to handle filenames with apostrophes ('single quotes').You'd better check the actual contents of the 2 variables you use before executing the file copy.
Another question: why do you typecast the filenames to PChar? Copyfile accepts normal string parms.
Try the CopyFile function in the FileUtil unit.BTW: were you using JwaWinBase.FileCopy?If so, that function is not UTF8 compliant.Before calling that function you should translate the source and destination name to ansi strings and then it does work (even with accented characters).
varfullpathsrc: string;beginfullpathsrc := 'Björk - Possibly Maybe.mp3';if fileexists('C:\music\' + fullpathsrc) = false then showmessage('File Does Not Exist');end;