Create folder for each folder in folder based on filename

Hi. I am very new to UiPath. I am trying to solve a problem and I am halfway there. In directory “C:\Users\krda\OneDrive - Modum kommune\Faggruppe VA\Rørinspeksjoner\UiPath test” I have two subfolders. Inside these subfolders there are some pdf files and some mp4 files. I want to create folders for every mp4 file inside each subfolder. The name of these created folders need to be the same as mp4 filename. Also inside these two subfolders I need to create an Excel workbook. This workbook wil be the same for each subfolder.

I am able to do this one subfolder at a time thanks to this post
How to create a folder for each file and move the files into that folder? - Help / Studio - UiPath Community Forum

But I am not able to apply this method using the “For each folder in folder” activity. A pointer in the right direction will be appreciated.

Kristoffer
Norway

Hi @krda,

Just add the code that you have inside “for each folder in folder”:

Let me know how it goes.

Juan P.

Hey @krda
try this:

allMp4Files (IEnumerable<String>) = Directory.GetDirectories("C:\Users\krda\OneDrive - Modum kommune\Faggruppe VA\Rørinspeksjoner\UiPath test").
SelectMany(Function(dir) Directory.GetFiles(dir, "*.mp4")).ToList()

Use a “For Each” activity to iterate through allMp4Files and perform actions like creating folders.

Hi, sorry for late reply. Weekend happened :slight_smile: I tried your solution @juan.porras1. In the "create folder step I get the error message “Create Folder: Value cannot be null. (Parameter ‘path1’)”. The code for folder name is “Path.Combine(folderPath, Split(CurrentFile.Name, “.”)(0))”. As I said I used this code from an post in these forums. This was copy paste, and I dont fully understand what that code actually does.

Thanks for helping me!

Kristoffer

Hi @krda,

That’s because folderPath is probably empty. Inside your “Create Folder” activity you can write: CurrentFile.FullName.Split(“.”)(0). Then change the move file parameters as the image.

This is the code file, I just tested it and it worked as expected:
Folders.xaml (9.3 KB)