Hi, I would like to move excel files from one folder to another.
But i only want to move some of the files instead of all the files.
For eg, i want to move A_310123 and D310123 only, but how do i write the condition with the file name contains A_* and D_*, as the date changes every month…
=> Assign → ListFiles (List Datatype) = Directory.GetFiles(“Folder Path”,“*.xlsx”)
=> Iterate the ListFiles variable to iterate with for each activity.
=> Inside for each place the Assign activity and store the file name in variable
=> Assign → EachFile = System.IO.Path.GetFileNameWithoutExtension(currentItem)
=> condition in If condition → EachFile.StartsWith(“A”) or EachFile.StartsWith(“C”)
=> In then block place the move file to move files from one folder to another foler.
Assign - sourceFolderPath = “C:\SourceFolder” // Replace with your actual source folder path
Assign - destinationFolderPath = “C:\DestinationFolder” // Replace with your actual destination folder path
Assign - filePatterns = {“A_", "D_”} // An array containing the file patterns to match
Assign - filesToMove = Directory.GetFiles(sourceFolderPath, “*.xlsx”) // Get all Excel files in the source folder
For Each - TypeArgument: String, Values: filesToMove
// Loop through each file in the source folder
For Each - TypeArgument: String, Values: filePattern in filePatterns
// Loop through each file pattern (“A_" and "D_”)
If - Condition: Path.GetFileNameWithoutExtension(item).StartsWith(filePattern)
// Check if the file name without extension starts with “A_” or “D_”
Assign - destinationFilePath = Path.Combine(destinationFolderPath, Path.GetFileName(item))
// Combine destination folder path with the file name to get the destination file path
File.Move(item, destinationFilePath)
// Move the file to the destination folder
End If
End For
End For
Use for each file in folder and indicate the files folder path
Use and if condition and in if use the syntax as CurrentFile.Name.StartsWith("A") or CurrentFile.Name.StartsWith("D")
And within this use the move file activity.
Assign Activity:
arrOfFilePaths | String() - String array =
(From fi In New DirectoryInfo(“Path”).GetFiles(“*.xlsx”)
Where New String() {“A”,“D”}.Any(Function (x) fi.Name.StartsWith(x))
Select fp = fi.FullName).toArray
Then loop over arrOfFilePaths e.g. with a for each actvitiy
@Joanna2
In the filter expression give"*.csv"
Check the filepath by sending a message box whether displaying correctly or not of the move file activity