Question
Claysys Technologies Inc
IN
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.
Attached Screenshots.
-
Like (0)
Rupa minupuri -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accenture
IN
Hi,
Make sure you give the destination path correctly.
In your case
Source: F:/test/testFile.txt
Destination: F:/test/Processed/testFile.txt
Also destination folder should not contain file testFile.txt.
Claysys Technologies Inc
IN
Yeah, its working for a txt file, but not for a xlsx file format. How can I resolve that?
Digital Fast Forward
US
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.
Claysys Technologies Inc
IN
Hi Nia,
Thanks for the update. But it seems to be not working for me. I have tried the same as you showed in the screenshot. Bad luck!!!. Still returning as false. PFA.
Infosys
IN
It should work 100%. There is no doubt.
Processed folder is exist? If no then create that folder.
Claysys Technologies Inc
IN
Yes. It exists. That's why the text file successfully moved. But didn't work for excel.
Infosys
IN
OMG surprise. Which version of pega robotics?
Work around: if you know .net then write script as below.
Add using System.IO (in namespace section)
public void MoveFile(string SourceFile, string TargetFile)
{
File.Move(SourceFile, TargetFile);
}
Claysys Technologies Inc
IN
No way...
Pegasystems Inc.
US
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.
Claysys Technologies Inc
IN
Thanks for all the replies...!
Bad luck for me, not any of the methods worked for me. I have done the task by invoking PowerShell script.
Pegasystems Inc.
US
We have added a MoveFile method that allows you to overwrite an existing file to the FileUtils in version Proprietary information hidden along with some other methods that should be helpful.
- MoveFile moves a file to a new destination and overwrites the file, if it already exists.
- CopyDirectory provides two overloaded methods to copy a directory from the source to a new destination. One method helps to overwrite the destination, if it is already present.
- FindInFiles provides two overloaded methods to search for specific text in a directory of files. One method accepts wildcard searchPatterns along with searchText.
- RenameDirectory renames a directory to the specified name.