Move file to Folder or Create folder if it doesn't Exist

Hi,
I’m getting the error “Move File: Value cannot be null. (Parameter ‘path1’)
I’m trying to create folders for files that are within the folder called files. I have files that are named differently and the data comes from an excel file. I want my process to move the file to the folder if it exists but if the folder doesn’t exist, then it should create the folder and then move the file to that folder.
Main - Copy.xaml (12.6 KB)

Document2- Temp1
Temp2 -picture
Temp3- pdf file
image-Temp4

image

@Jonnathan_Fernandez

As per error you provided a blank value for parameter in move file

You can use a create folder first…which will create if not exists else just moves forward

Then you can loop your excel and move files accordingly…hope your excel contains fullpath

Cheers

Hi @Jonnathan_Fernandez

You haven’t initialized any path to the SourceFilePath variable. If it is empty then where the bot will the files from the path.
Check the folder path exist or not in Folder exist activity. This activity give bool value.
Check the bool value with If condition Bool = True, In then block use create folder activity to create the folder.
Use read range workbook activity to read the data from the excel.
Take an assign activity and store the files in a array variable by Directory.getfiles(“Give Path here”)
Use for each row in datatable activity to iterate the rows in datatable.
Inside loop use if condition to check the array variable and row value equal.
If equal in then block use the Move file activity to move from source to the destination folder.

Hope it helps!!

The folder exist activity is boolean value. I used the assign activity Directory.getfiles but keep getting the same error

@Jonnathan_Fernandez

Looks like your directory.Getfiles is returning no values or you are passing a variable which is empty to move file…please check the same

Cheers

Iterate the Directory.get files with for each loop and then compare the for each row in datatable value with For each value.

Then inside the If condition use the move file activity.

Hope you understand!!

I have do the workflow, check the below workflow
Main.xaml (16.9 KB)

- Step1 -> Read the excel and stored in a datatable by using read range workbook activity.
- Step2 -> Use assign activity and create a array variable to store the files in the folder
              -> Assign -> Files (Array) = Directory.GetFiles("Give the folder path here")
- Step3 -> Use for each row in datatable to iterate the datatable
- Step4 -> Use for each loop to iterate the Files(Array) variable to iterate the every file in the folder
- Step4 -> Use assign activity to store the file name with out extension
              -> Assign -> FileName (String) = System.IO.Path.GetFileNameWithoutExtension(currentItem.ToString)
- Step 5 -> Compare the Current row in for each row in datatable with the file name
               -> If -> Currentrow("Column name").toString.equals(FileName)
                   -> In then block give the move file activity to move the current file to another folder

Hope you got the solution!!

Hi @Jonnathan_Fernandez

Use .contains method in if condition

  1. Path = Directory.GetFiles(“YourFolderPathHere”).Select(Function(file) Path.GetFileName(file)).ToArray()
  2. For each file in folder
  3. Assign:name = currentFile.GetFileName()
  4. If(path.contains(name))
    —> move file
    else
    —> Create folder