Recreate folder path

I have a scenario where I am scanning network directories recursively looking for files with certain attributes. When I find find files with matching attributes, I want to move them to an identical directory structure on another server. Rather than doing the manual work to recreate the directory structure, I would like to use the file path to do that automatically. Has anyone parsed a structure and used the File Command ==> Create folder iteratively to do that?

Example: \servername\directory1\directory2\directory3\file to be created on another server: \newservername\directory1\directory2\directory3 and then moving the file to that new structure. It seems that it would be very useful to have an action that could do that automatically.

I may have answered my own question. I think this is doable with keepafter using instances: keepafter(‘a/b/c/d’, ‘/’, 2) //Returns ‘c/d’ (Keep text after the second instance of ‘/’)

If anyone has done this and ca post sample expression it would be appreciated.

Thanks!

Hi Casey,

How about this:

let path = '\servername\directory1\directory2\directory3\file.txt'
'\newservername\' & keepafter(keepbefore(path, '\', -1),'\', 2)

Also, see the attached project.
new-path.morph (2.7 KB)

Hi Dmitry,

I think my original post was not clear. Let me try to clearer. I am recursively scanning a network folder looking for files older than 7 years. In my example, I might find a file like so:

\server name\parent folder\child 1\child2\child 3\file.txt

Because the file is > 7 years old, I want to move it to a new server to archive for 6 months before final deletion. I want to create the exact same directory structure on the new server, but it doesn’t exist yet on that new server. So my goal is to parse the above UNC string and create the directories using the File Command action with Create Directory function. But I can only do that one folder at a time to the best of my knowledge. So using the file command, I would need to first create the Parent directory, and then create each child directory using the directory above it as the parent directory.

File Command Create Directory ==> Parent
File Command Create Directory ==> Child 1, Parent Directory
File Command Create Directory ==> Child 2, Parent Directory (Child 1)
File Command Create Directory ==> Child 3, Parent Directory (Child 2)

Hopefully, that is clearer than my original post.

Thanks!

Thanks for the clarification, Casey.

Creating multiple nested folders with the “File command” action can be tedious, although possible. I would just use the “Run program” action to run a Windows command, such as:

 mkdir directory1\directory2\directory3\

The mkdir command creates all the missing subfolders automatically. Note that you might need to check the “Ignore errors” option because this command would fail if the subfolders already exist.

Alternatively, if you want to do it with the “File command” action, you can do it as in the project below.
new-path.morph (7.2 KB)