Posted: 19 Nov 2019 5:03 EST Last activity: 28 Dec 2019 9:52 EST
Move a file from one folder to another folder using pega
Both the File.Move method and fileUtils MoveFile method is not working. Throwing an exception(Cannot create a file when that file already exists.) for File.Move method and returning a false for MoveFile method. Please give me a solution.
Hi Aswani, in order to resolve and move for an xlsx file format, you should place the first full path of the xlsx file under the sourcePath (include the file name and extension) value, ex. (F:\Documents\test\testFile.xlsx), and in the destinationPath value you should include the destination directory, in addition to the filename and extension of the file that you are using to move initially, ex (F:\Documents\Processed\testFile.xlsx). This should work. I have attached a screenshot as well. This is using the MoveFile method under the FileUtils tool.
Your original exception was that it couldn't create the file because it already exists. Move doesn't allow you to overwrite the file - you must delete it first. This is pretty straightforward using other methods available in FileUtils.