How could I watch a root directory, and get the full file path of document placed in sub-directory

Basically I have a branching file system that is to help me store and catagorize invoices. When a user places a file in any of the sub-directories, I want to be able to extract the text (I use a program that UI Path runs to do that) and then export the text to a separate folder. I’ve tried using File Watcher, but that only returns the name of the file, not the path, and without the path my sequence won’t know where to look to find it. I’m not too experienced with this, as I’ve only started working with UI Path 2 days ago, so please explain things very plainly to me. Thank you to anyone who can help!

will the file names be unique? If so you could use file watcher to get the name of the file. Then use this within a Directory.GetFiles(RootPath,FileName,SearchOption.AllDirectories). This will return an IEnumerable<string> but should only have the one file. So you could put it all in an assign activity and say MyFile = Directory.GetFiles(RootPath,FileName,SearchOption.AllDirectories)(0)

RootPath is a string that is the root directory.
FileName is a string that you get from FileWatcher containing the filename. I am assuming it includes the extension. If it doesn’t then you should change that portion of the GetFiles method to be FileName + “*”
MyFile is a string that is the full file path including extension. If you want the file path without extension change the assign to be MyFile = Path.GetFileNameWithoutExtension(Directory.GetFiles(RootPath,FileName,SearchOption.AllDirectories)(0))

3 Likes

Wow this sounds really genius! I gotta figure out how to do the “Directory.GetFiles” thing because I don’t know where to put code, but I’ll look into that tomorrow, thank you so much that sounds really genius.

You can put it all in an assign activity. Assign MyFile = Directory.GetFiles(RootPath,FileName,SearchOption.AllDirectories)(0) and it will give you a string variable called myfile containing the full file path :slight_smile: I can mock up a quick .XAML showing what i mean too if you need further clarification - always happy to help!

1 Like

That totally worked! Thank you so much for the help with my issue.

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