tags:

views:

37

answers:

1

I need to copy a number of image files from a given location to a given directory, i need the original filename preserved.

can it be something like url->copy(img14, ImgPath);

where img14 is the path to the file including the filename and the imgpath is the destination directory.

img14 can be : /home/obscurant1st/Downloads/aaa.jpeg or C:\abcd\asada.jpeg

Plase Note: I have to use variables. I cannot use the exact path in the code!

+3  A: 

Use QFile::copy. Note that both parameters are full file paths, so you need to create the destination file path using the destination directory and source file name. And there QFileInfo::fileName() will probably be useful.

Edit:

Just create a function that gets the source file path and the destination directory:

bool CopyFile(const QString& sourceFile, const QString& destinationDir)
{
    QFileInfo fileInfo(sourceFile);
    QString destinationFile = destinationDir + "/" + fileInfo.fileName();
    bool result = QFile::copy(sourceFile, destinationFile);
    return result;
}
Roku
I need to use variables! So this will not work.As of now I am trying QProcess with StartDetached("cp", QStringList() << var << var2).But if there is some other way without using the system commands, pls let me know! :)
oDx
You need to create a string variable that contains the full path.
mskfisher
thx man, now with this edited part it works excellent. :)This is what i wanted!
oDx