Quantcast
Viewing all articles
Browse latest Browse all 3160

#0396 SQL Server SSIS Move and rename a file “Could not find part o ...

When working with disconnected sources or remote systems in SSIS,source data is often received in theform of files. A common requirement is to rename the file once the data import/processing is completed.

I looked at the File System task inmy previous post. The file system task appears to be the best way to implement this requirement. However, we run into something that is unexpected:

The “Move File” operationmoves a file from one folder to another. It does not rename the file.

Basic Scenario

Let me leverage the same example as I had inmy previous post. I have a set of files in afolder and an SSIS package that is configured to rename thefiles.


Image may be NSFW.
Clik here to view.
#0396   SQL Server   SSIS   Move and rename a file   “Could not find part o ...

Folder with input files which need to be renamed once processing is complete

The destination file name comes from an expression that uses basic string concatenation to achieve the required target file name. The expression used in thedestination file name variable is provided below.

@[User::SourceFolder] + SUBSTRING(@[User::FileName], 1, FINDSTRING(@[User::FileName],".",1) -1 ) + (DT_WSTR,4)YEAR(GETDATE()) + (DT_WSTR,2)MONTH(GETDATE()) + (DT_WSTR,2)DAY(GETDATE()) + SUBSTRING(@[User::FileName], FINDSTRING(@[User::FileName],".",1), LEN(@[User::FileName]))
Image may be NSFW.
Clik here to view.
#0396   SQL Server   SSIS   Move and rename a file   “Could not find part o ...

Variable to populate the new name for the output file using an Expression

Move File Operation

The File System Task in this package has been designed to use variables as the source and destination file names. The File System task is configured to perform a“Move File” operation.


Image may be NSFW.
Clik here to view.
#0396   SQL Server   SSIS   Move and rename a file   “Could not find part o ...

File System Task in the “Move File” configuration

Upon running the SSIS package, no files are processed and we run into an error.


Image may be NSFW.
Clik here to view.
#0396   SQL Server   SSIS   Move and rename a file   “Could not find part o ...

Execution Error when running the File System Task


Image may be NSFW.
Clik here to view.
#0396   SQL Server   SSIS   Move and rename a file   “Could not find part o ...

“Could not find a part of the path.” error in the File System task “Move File” configuration

Looking at the error in detail, wesee that the error is:

Could not find a part of the path.

Using the Rename File configuration

If we change the operation type to the “Rename File” configuration, we can see that the movement is successful.


Image may be NSFW.
Clik here to view.
#0396   SQL Server   SSIS   Move and rename a file   “Could not find part o ...

File System Task configuration using “Rename File” mode where input & output file names are supplied via variables


Image may be NSFW.
Clik here to view.
#0396   SQL Server   SSIS   Move and rename a file   “Could not find part o ...

Moving files using File System task with “Rename File” operation

Behind the scenes

So, why is the File System task notbehaving as expected? If the File System configuration is set to “Move File”, whydid the files not move to the target folder?

The reason is quite simple: “Move File” only moves a file it cannot rename a file during the movement of the file.

In short, one has to configure the File System task in a “Rename File” configuration ifa file has to be renamed irrespective of whether the rename isin-place or in a different folder.

Until we meet next time,

Be courteous. Drive responsibly.


Viewing all articles
Browse latest Browse all 3160

Trending Articles