View difference between Paste ID: uUFiLJdB and n7MDwCYd
SHOW: | | - or go back to the newest paste.
1
Rename PATTERN * TO *
2
@script jscript
3
4
// Dopus rename script (http://www.gpsoft.com.au/)
5
// Add folder name after file name
6
7
DOpus.ClearOutput();
8
DOpus.output(DOpus.version);
9
10
function Rename::GetNewName2(strFileName, strFilePath, _fIsFolder, strOldName, strNewName) {
11
	
12
	if(_fIsFolder){
13
	    DOpus.output(strFileName +" Is Folder");
14
	    return strFileName;
15
	}
16
	parentFolder = GetPathLastFolder(new String(strFilePath)).folder;
17
	var fname = strFileName.replace(/(.*)(\.[^.]+)$/, "$1");
18
	var fextn = strFileName.replace(/(.*)(\.[^.]+)$/, "$2");
19
	DOpus.output("fname: "+fname + fextn);
20
	var re = new RegExp(parentFolder+'$');
21
	//DOpus.output("regExp: "+fname.match(re));
22
	if (fname.match(re)) {
23
		DOpus.output("Not Rename " + strFileName);
24
		return strFileName
25
	}
26
	DOpus.output("Rename " + strFileName + " to " + fname +' '+ parentFolder + fextn);
27
	return fname +' '+ parentFolder + fextn;
28
}
29
30
function GetPathLastFolder(mypath) {
31
	mypath = mypath.replace(/(^(\s|\/|\\)+)|((\s|\/|\\)+$)/g, "");
32
	lastIndex = mypath.lastIndexOf('\\');
33
	if (lastIndex == -1 || (lastIndex + 1) == mypath.length) return {
34
		folder: mypath,
35
		parentPath: ""
36
	};
37
	return {
38
		folder: mypath.substring(lastIndex + 1),
39
		parentPath: mypath.substring(0, lastIndex)
40
	};
41
}