Find created folder name in FTP and move file to that FTP folder

FTP root Path is = “/”
it has 1 folder = Test

I’m creating a folder inside TEST folder by uploading a simple tekst (varCurrFileName is a holding text file name) file to it. like this

image

it works but I want to know that created folder name as I want to move some more files which is located on root of FTP . Means want to move files from “/” to “/TEST/22-04-2024 13:12:56” if that is the current created folder when i uploaded the file.

How to find the folder name and then move all files with for each loop. I tried but its not working.
can someone help.

@Ellen,

You can use Enumerate Objects activity to get all the subfolders and use then as per your requirement.

Thanks,
Ashok :slight_smile:

Just store the folder name in a variable then you already have the value, you don’t have to find it.

Assign folderName = “/Test/” + Now.ToString(“dd-MM-yyyy”)
Upload Files, Remote Path = folderName

Then you just use the folderName variable anywhere you need it.

The challenge here is that standard FTP commands don’t directly provide a way to retrieve the name of the newly created folder after uploading a file. However, we can achieve this using a two-step approach:

@Ellen you need to try this to and need to modify according to your test logic.

Approach 1: Storing the Folder Name During Upload (by Paul)

  1. Assign Folder Name: Before uploading the file, use an “Assign” activity to construct the desired folder name dynamically. You can use the Now.ToString("dd-MM-yyyy HH:mm:ss") format to include the current date and time in the folder name.

folderName = "/Test/" + Now.ToString("dd-MM-yyyy HH:mm:ss")

  1. Upload with Constructed Path: In the “Upload File” activity, set the “Remote Path” property to the folderName variable. This ensures the file is uploaded to the newly created folder with the timestamp.
  2. Move Files Using Stored Name: After upload, you can directly use the folderName variable to construct the target paths for moving files from the root directory.

Approach 2: Using Enumerate Objects (by Ashok)

  1. Enumerate Folders (After Upload): After uploading the file, use the “Enumerate Folders” activity within a sequence. Set the “Folder Path” property to “/Test” to list all subfolders within the “Test” folder.
  2. Filter for Newest Folder: Use a “For Each” activity to iterate through the enumerated folders. Inside the loop, you can compare the folder creation time (obtained using system functions) with the upload time to identify the newly created folder.
  3. Extract Folder Name: Once you identify the newest folder, extract its name and store it in a variable.
  4. Move Files Using Extracted Name: Similar to Approach 1, use the extracted folder name to construct target paths for moving files from the root directory.

Choosing the Right Approach:

  • Approach 1 is simpler and more efficient if you can control the folder naming convention (using timestamps).
  • Approach 2 is more flexible if you need to handle scenarios where the folder name might not follow a predictable pattern.

Hi Team, I am having issues with FTP activity. Getting the below error when using Enumerate Objects’
Enumerate Objects: One or more errors occurred. (Unsupported object type encountered.)

I can find my directory exists using Directory exist activity. But when used the same Remote Path I am getting this error.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.