檔案系統工作File System Task

「檔案系統」工作會在檔案系統中的檔案和目錄上執行作業。The File System task performs operations on files and directories in the file system. 例如,封裝可使用「檔案系統」工作建立、移動或刪除目錄和檔案。For example, by using the File System task, a package can create, move, or delete directories and files. 您也可以使用「檔案系統」工作設定檔案和目錄的屬性。You can also use the File System task to set attributes on files and directories. 例如,「檔案系統」工作可將檔案設為隱藏或唯讀。For example, the File System task can make files hidden or read-only.

所有「檔案系統」工作作業均使用來源,其可為檔案或目錄。All File System task operations use a source, which can be a file or a directory. 例如,工作所複製的檔案或刪除的目錄即為來源。For example, the file that the task copies or the directory it deletes is a source. 來源可使用指向目錄或檔案的「檔案」連接管理員指定,或藉由提供包含來源路徑的變數名稱指定。The source can be specified by using a File connection manager that points to the directory or file or by providing the name of a variable that contains the source path. 如需詳細資訊,請參閱檔案連線管理員Integration Services (SSIS) 變數For more information, see File Connection Manager and Integration Services (SSIS) Variables.

複製和移動檔案與目錄以及重新命名檔案的作業會使用目的地和來源。The operations that copy and move file and directories and rename files use a destination and a source. 目的地是使用「檔案」連接管理員或變數指定。The destination is specified by using a File connection manager or a variable. 檔案系統工作的作業可設定為允許覆寫目的地檔案和目錄。File system task operations can be configured to permit overwriting of destination files and directories. 建立新目錄的作業可設定為當目錄已存在時使用具有指定名稱的現有目錄,而不會失敗。The operation that creates a new directory can be configured to use an existing directory that has the specified name instead of failing when the directory already exists.

預先定義的檔案系統作業Predefined File System Operations

「檔案系統」工作包括一組預先定義的作業。The File System task includes a predefined set of operations. 下表描述這些作業。The following table describes these operations.

運算Operation 說明Description
複製目錄Copy directory 將資料夾從一個位置複製到另一個。Copies a folder from one location to another.
複製檔案Copy file 將檔案從一個位置複製到另一個。Copies a file from one location to another.
建立目錄Create directory 在指定的位置建立資料夾。Creates a folder in a specified location.
刪除目錄Delete directory 刪除指定位置的資料夾。Deletes a folder in a specified location.
刪除目錄內容Delete directory content 刪除某個資料夾中的所有檔案和資料夾。Deletes all files and folders in a folder.
刪除檔案Delete file 刪除指定位置的檔案。Deletes a file in a specified location.
移動目錄Move directory 將資料夾從一個位置移到另一個。Moves a folder from one location to another.
移動檔案Move file 將檔案從一個位置移到另一個。Moves a file from one location to another.
重新命名檔案Rename file 重新命名指定位置的檔案。Renames a file in a specified location.
設定屬性Set attributes 設定檔案和資料夾的屬性。Sets attributes on files and folders. 屬性包括「封存」、「隱藏」、「一般」「唯讀」和「系統」。Attributes include Archive, Hidden, Normal, ReadOnly, and System. 「一般」表示無任何屬性,且不可與其他屬性結合。Normal is the lack of attributes, and it cannot be combined with other attributes. 其他所有屬性都可互相結合使用。All other attributes can be used in combination.

「檔案系統」工作會在單一檔案或目錄上運作。The File System task operates on a single file or directory. 因此,這項工作不支援使用萬用字元在多個檔案上執行相同的作業。Therefore, this task does not support the use of wildcard characters to perform the same operation on multiple files. 為了要讓「檔案系統」工作在多個檔案或目錄上重複作業,請將「檔案系統」工作放入 Foreach 迴圈容器內,如以下步驟所述:To have the File System task repeat an operation on multiple files or directories, put the File System task in a Foreach Loop container, as described in the following steps:

  • 設定 Foreach 迴圈容器 :在 [Foreach 迴圈編輯器] 的 [集合] 頁面上,將列舉值設定為 [Foreach 檔案列舉值] 然後輸入萬用字元運算式,做為 [檔案]的列舉值組態。Configure the Foreach Loop container On the Collection page of the Foreach Loop Editor, set the enumerator to Foreach File Enumerator and enter the wildcard expression as the enumerator configuration for Files. 在 [Foreach 迴圈編輯器] 的 [變數對應] 頁面上,對應您要使用的變數,以便將檔案名稱傳遞到 [檔案系統] 工作,一次一個。On the Variable Mappings page of the Foreach Loop Editor, map a variable that you want to use to pass the file names one at a time to the File System task.

  • 加入和設定檔案系統工作 :將「檔案系統」工作加入到「Foreach 迴圈」容易。Add and configure a File System task Add a File System task to the Foreach Loop container. 在「檔案系統工作編輯器」的 [一般] 頁面上,將 [SourceVariable][DestinationVariable] 屬性設定為您在「Foreach 迴圈」容器中定義的變數。On the General page of the File System Task Editor, set the SourceVariable or DestinationVariable property to the variable that you defined in the Foreach Loop container.

檔案系統工作上可用的自訂記錄項目Custom Log Entries Available on the File System Task

下表描述「檔案系統」工作的自訂記錄項目。The following table describes the custom log entry for the File System task. 如需詳細資訊,請參閱 Integration Services (SSIS) 記錄For more information, see Integration Services (SSIS) Logging.

記錄項目Log entry 說明Description
FileSystemOperationFileSystemOperation 報告工作執行的作業。Reports the operation that the task performs. 記錄項目會在檔案系統作業開始時寫入,項目中包含有關來源和目的地的資訊。The log entry is written when the file system operation starts and includes information about the source and destination.

設定檔案系統工作Configuring the File System Task

您可以透過「 SSISSSIS 設計師」或以程式設計方式設定屬性。You can set properties through SSISSSIS Designer or programmatically.

如需有關可在「 SSISSSIS 設計師」中設定之屬性的詳細資訊,請參閱下列主題:For more information about the properties that you can set in SSISSSIS Designer, see the following topics:

Integration ServicesIntegration Services 包括下載和上傳資料檔以及管理伺服器上目錄的工作。 includes a task that downloads and uploads data files and manages directories on servers. 如需相關資訊,請參閱 FTP TaskFor more information, see FTP Task.

檔案系統工作編輯器 (一般頁面)File System Task Editor (General Page)

使用 [檔案系統工作編輯器] 對話方塊的 [一般] 頁面,即可設定工作執行的檔案系統作業。Use the General page of the File System Task Editor dialog to configure the file system operation that the task performs.

您必須透過設定 SourceConnection 和 DestinationConnection 屬性,以指定來源和目的地連線管理員。You must specify a source and destination connection manager by setting the SourceConnection and DestinationConnection properties. 您可以提供指向工作做為來源或目的地使用之檔案的檔案連接管理員名稱,而如果檔案路徑是儲存在變數中,則可以提供變數的名稱。You can either provide the names of File connection managers that point to the files that the task uses as a source or destination, or if the paths of the files are stored in variables, you can provide the names of the variables. 若要使用變數來儲存檔案路徑,您必須先將來源連接的 [IsSourcePathVariable] 選項和目的地連接的 [IsDestinationPatheVariable] 選項設定為 [True]。To use variables to store the file paths, you must set first set the IsSourcePathVariable option for the source connection and the IsDestinationPatheVariable option for the destination connection to True. 接著您就可以選擇要使用的現有系統或使用者自訂變數,或是建立新的變數。You can then choose the existing system or user-defined variables to use, or you can create new variables. 您可以在 [加入變數] 對話方塊中,設定和指定變數的範圍。In the Add Variable dialog box, you can configure and specify the scope of the variables. 此範圍必須是「檔案系統」工作或父容器。The scope must be the File System task or a parent container. 如需詳細資訊,請參閱 Integration Services (SSIS) 變數在封裝中使用變數For more information see, Integration Services (SSIS) Variables and Use Variables in Packages.

注意

若要覆寫您針對 SourceConnectionDestinationConnection 屬性選取的變數,請針對 [來源] 和 [目的地] 屬性輸入運算式。To override the variables you selected for the SourceConnection and DestinationConnection properties, enter an expression for the Source and Destination properties. 您可在 [檔案系統工作編輯器] 的 [運算式] 頁面上輸入運算式。You enter expressions on the Expressions page of the File System Task Editor. 例如,為了設定做為工作目的地使用的檔案路徑,在某些情況下您可能想要使用變數 A,而在其他情況下使用變數 B。For example, to set the path of the files that the task uses as a destination, you may want to use variable A under certain conditions and use variable B under other conditions.

注意

「檔案系統」工作會在單一檔案或目錄上運作。The File System task operates on a single file or directory. 因此,這項工作不支援使用萬用字元在多個檔案或目錄上執行相同的作業。Therefore, this task does not support the use of wildcard characters to perform the same operation on multiple files or directories. 為了要讓「檔案系統」工作在多個檔案或目錄上重複作業,請將此「檔案系統」工作放入 Foreach 迴圈容器內。To have the File System task repeat an operation on multiple files or directories, put the File System task in a Foreach Loop container. 如需詳細資訊,請參閱 檔案系統工作For more information, see File System Task.

您可以使用運算式,將不同的變數用於You can use expressions to use different variables for the

選項。Options

IsDestinationPathVariableIsDestinationPathVariable
指出目的地路徑是否儲存在變數中。Indicate whether the destination path is stored in a variable. 這個屬性具有下表中所列的選項。This property has the options listed in the following table.

ValueValue 說明Description
TrueTrue 目的地路徑儲存在變數中。The destination path is stored in a variable. 選取這個值會顯示動態選項 [DestinationVariable]。Selecting this value displays the dynamic option, DestinationVariable.
FalseFalse 目的地路徑是在檔案連接管理員中指定。The destination path is specified in a File connection manager. 選取這個值會顯示動態選項 [DestinationConnection]。Selecting this value displays the dynamic option, DestinationConnection.

OverwriteDestinationOverwriteDestination
指定作業是否可覆寫目的地目錄中的檔案。Specify whether the operation can overwrite files in the destination directory.

名稱Name
為檔案系統工作提供唯一的名稱。Provide a unique name for the File System task. 這個名稱是作為工作圖示中的標籤使用。This name is used as the label in the task icon.

注意

工作名稱在封裝內必須是唯一的。Task names must be unique within a package.

說明Description
輸入檔案系統工作的描述。Type a description of the File System task.

運算Operation
選取要執行的檔案系統作業。Select the file-system operation to perform. 這個屬性具有下表中所列的選項。This property has the options listed in the following table.

ValueValue 說明Description
複製目錄Copy directory 複製目錄。Copy a directory. 選取此值會顯示來源與目的地的動態選項。Selecting this value displays the dynamic options for a source and destination.
複製檔案Copy file 複製檔案。Copy a file. 選取此值會顯示來源與目的地的動態選項。Selecting this value displays the dynamic options for a source and destination.
建立目錄Create directory 建立目錄。Create a directory. 選取此值會顯示來源和目的地目錄的動態選項。Selecting this value displays the dynamic options for a source and a destination directory.
刪除目錄Delete directory 刪除目錄。Delete a directory. 選取此值會顯示來源的動態選項。Selecting this value displays the dynamic options for a source.
刪除目錄內容Delete directory content 刪除目錄的內容。Delete the content of a directory. 選取此值會顯示來源的動態選項。Selecting this value displays the dynamic options for a source.
刪除檔案Delete file 刪除檔案。Delete a file. 選取此值會顯示來源的動態選項。Selecting this value displays the dynamic options for a source.
移動目錄Move directory 移動目錄。Move a directory. 選取此值會顯示來源與目的地的動態選項。Selecting this value displays the dynamic options for a source and destination.
移動檔案Move file 移動檔案。Move a file. 選取此值會顯示來源與目的地的動態選項。Selecting this value displays the dynamic options for a source and destination. 當移動檔案時,請勿在您提供當做目的地的目錄路徑內包含檔案名稱。When moving a file, do not include a file name in the directory path that you provide as the destination.
重新命名檔案Rename file 重新命名檔案。Rename a file. 選取此值會顯示來源與目的地的動態選項。Selecting this value displays the dynamic options for a source and destination. 當重新命名檔案時,請在您提供當做目的地的目錄路徑內包含新的檔案名稱。When renaming a file, include the new file name in the directory path that you provide for the destination.
設定屬性Set attributes 設定檔案或目錄的屬性。Set the attributes of a file or directory. 選取此值會顯示來源與作業的動態選項。Selecting this value displays the dynamic options for a source and operation.

IsSourcePathVariableIsSourcePathVariable
指出目的地路徑是否儲存在變數中。Indicate whether the destination path is stored in a variable. 這個屬性具有下表中所列的選項。This property has the options listed in the following table.

ValueValue
TrueTrue 目的地路徑儲存在變數中。The destination path is stored in a variable. 選取此值會顯示動態選項 [SourceVariable]。Selecting this value displays the dynamic option, SourceVariable.
FalseFalse 目的地路徑是在檔案連接管理員中指定。The destination path is specified in a File connection manager. 選取這個值會顯示動態選項 [DestinationVariable]。Selecting this value displays the dynamic option, DestinationVariable.

IsDestinationPathVariable 動態選項IsDestinationPathVariable Dynamic Options

IsDestinationPathVariable = TrueIsDestinationPathVariable = True

DestinationVariableDestinationVariable
在清單中,選取變數名稱,或按一下<新增變數...> 若要建立新的變數。Select the variable name in the list, or click <New variable...> to create a new variable.

相關主題Integration Services (SSIS) 變數加入變數Related Topics: Integration Services (SSIS) Variables, Add Variable

IsDestinationPathVariable = FalseIsDestinationPathVariable = False

DestinationConnectionDestinationConnection
在清單中,選取檔案連接管理員,或按一下<新增連接...> 以建立新的連接管理員。Select a File connection manager in the list, or click <New connection...> to create a new connection manager.

相關主題: File Connection ManagerFile Connection Manager EditorRelated Topics: File Connection Manager, File Connection Manager Editor

IsSourcePathVariable 動態選項IsSourcePathVariable Dynamic Options

IsSourcePathVariable = TrueIsSourcePathVariable = True

SourceVariableSourceVariable
在清單中,選取變數名稱,或按一下<新增變數...> 若要建立新的變數。Select the variable name in the list, or click <New variable...> to create a new variable.

相關主題Integration Services (SSIS) 變數加入變數Related Topics: Integration Services (SSIS) Variables, Add Variable

IsSourcePathVariable = FalseIsSourcePathVariable = False

SourceConnectionSourceConnection
在清單中,選取檔案連接管理員,或按一下<新增連接...> 以建立新的連接管理員。Select a File connection manager in the list, or click <New connection...> to create a new connection manager.

相關主題: 檔案連線管理員Related Topics: File Connection Manager

作業動態選項Operation Dynamic Options

作業 = 設定屬性Operation = Set Attributes

HiddenHidden
指出檔案或目錄是否可見。Indicate whether the file or directory is visible.

ReadOnlyReadOnly
指出檔案是否為唯讀。Indicate whether the file is read-only.

ArchiveArchive
指出檔案或目錄是否準備就緒,可供封存。Indicate whether the file or directory is ready for archiving.

系統System
指出檔案是否為作業系統檔案。Indicate whether the file is an operating system file.

作業 = 建立目錄Operation = Create directory

UseDirectoryIfExistsUseDirectoryIfExists
指出 [建立目錄] 作業是否會使用具有指定之名稱的現有目錄,而不是建立新的目錄。Indicates whether the Create directory operation uses an existing directory with the specified name instead of creating a new directory.

另請參閱See Also

Integration Services 工作 Integration Services Tasks
控制流程Control Flow