after trying so long on this didn't got the proper solution so have tried through java with the help of my colleague..thanks to him.
Would like to share the same if someone need it.
import java.io.File;
/**
* This class is search with start file character sequence and replace the file name with new character.
* @author nitin.choube
*
*/
public class SearchAndReplaceFileName
{
public static void main(String[] args)
{
//Parent file path from start searching files
File dir = new File("D:\\WS\\Upload");
// replace character string
final String replaceChar="XYZ";
// replace character string with
final String replaceCharWtih="ALB";
// file extension
final String fileExtension=".htm";
if(dir.isDirectory()){
File[] children = dir.listFiles();
iterateFile(children,replaceChar,replaceCharWtih,fileExtension);
}
}
/**
* This method is allow to search and replace file name.
* @param children
* @param replaceChar
* @param replaceCharWtih
* @param fileExtension
*/
public static void iterateFile(File[] children,String replaceChar,String replaceCharWtih,String fileExtension){
try {
for (int i=0; i<children.length; i++) {
// Get filename of file or directory
File file = children[i];
System.out.println("Getting all files in " + file.getCanonicalPath() + " including those in subdirectories");
if(file.isDirectory()){
File[] child = file.listFiles();
iterateFile(child,replaceChar,replaceCharWtih,fileExtension);
}else if(file.isFile()){
String extension = file.getName().substring(file.getName().lastIndexOf("."));
System.out.println("extracted file name is "+file.getName()+" and extension is ="+extension);
if(extension.equals(fileExtension)){
String fileName=file.getName().substring(0,file.getName().lastIndexOf(fileExtension));
if(fileName.startsWith(replaceChar)){
String newFileName=fileName.replace(replaceChar,replaceCharWtih);
file.renameTo(new File(file.getCanonicalPath().substring(0,file.getCanonicalPath().lastIndexOf("\\"))+"\\"+newFileName+fileExtension));
}else if(fileName.contains("_"+replaceChar+"_")){
String newFileName=fileName.replace(replaceChar,replaceCharWtih);
file.renameTo(new File(file.getCanonicalPath().substring(0,file.getCanonicalPath().lastIndexOf("\\"))+"\\"+newFileName+fileExtension));
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}