Hi Jake
Yes, there is a way to rename the file but it is a little complicated due to:
the object returned by ogscript.getFile is of type “File” and has a function called “renameTo” but it requires another “File” as an argument (not just a name)
ogscript.getFile only returns files that already exist
We can work around this by using ogscript.saveToFile to create a new empty “File” that we can retrieve with ogscript.getFile and pass as the argument to file.renameTo using a simple function like this:
function rename(oldPath, newName)
{
var file = ogscript.getFile(oldPath);
var newFilePath = file.getParent() + file.separator + newName;
ogscript.saveToFile(newFilePath, ‘’, true);
var newFile = ogscript.getFile(newFilePath);
newFile.delete();
file.renameTo(newFile);
}
The first argument for this function is the full path to the file and the second argument is just the new file name. This is an updated version of the panel with a button to exercise the feature:
function rename(oldPath, newName)
{
var file = ogscript.getFile(oldPath);
var newFilePath = file.getParent() + file.separator + newName;
ogscript.saveToFile(newFilePath, '', true);
var newFile = ogscript.getFile(newFilePath);
newFile.delete();
file.renameTo(newFile);
}
var file = ogscript.getFile(params.getValue('Starting_Directory', 0));
if (file != null && file.exists() && file.isDirectory())
{
var filter = params.getValue('extension', 0).trim(); //this would be optional
var list = file.list();
var filteredList = [];
for (var i = 0; i < list.length; i++)
{
if (filter == ‘*’ || list[i].toLowerCase().endsWith(filter)) //Check the filter
{
filteredList.push(list[i]);
}
}
if (filteredList.length == 0) //Put a blank if we have no files that match the filter
{
filteredList.push(“”);
}
var constraint = params.createStringChoiceConstraint(filteredList);
if (constraint != null)
{
params.replaceConstraint(‘File_List’, constraint);
}
}
/! block id=1003,1004,1005,1006,1008,1007 !/
rename((params.getValue(‘Starting_Directory’, 0) + params.getValue(‘File_List’, 0)), (params.getValue(‘File_List’, 0) + “.processed”));
/!!
!!/
/!!71c99d91d1ebb47d7c6a14d868f7faac!!/