简体   繁体   中英

SSIS Copy files from one location to another

I want to copy a specific file from one location to another. I have a Message Box that prints where the file is copied source and destination as per below:

在此处输入图片说明

I get the below error:

在此处输入图片说明

Based on File.Copy Method , The second parameter is the new file name not the directory:

The name of the destination file. This cannot be a directory or an existing file.

You need to use a similar logic:

FileCopy(filestocopy[p],targetDir + "\\" + Path.GetFileName(filestocopy[p]));

Also it is recommended to check if the file already exists in the directory:

if (!File.Exists(targetDir + "\\" + Path.GetFileName(filestocopy[p])))
    FileCopy(filestocopy[p],targetDir + "\\" + Path.GetFileName(filestocopy[p]));

If you need to overwrite any existing file you can add a boolean parameter :

FileCopy(filestocopy[p],targetDir + "\\" + Path.GetFileName(filestocopy[p]),true);

You need to specify the [file directory] + [File name] + [File extension] for the target parameter

So do something like this:

string destination = Path.Combine(targetDir, Path.GetFileName(filestocopy[p]));
File.Copy(filestocopy[p], destination);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM