Site logo

Increment

Increment file name example

function ProcessDocument(doc) {
	var oldDocPath = doc.filePath.absoluteURI;
	var newDocFile = new File(oldDocPath + "/Backup_" + doc.name);
	
	if (newDocFile.exists) { // Don't overwrite existing files
		var increment = 1;
		while (newDocFile.exists) {
			newDocFile = new File(oldDocPath + "/Backup" + "(" + increment++ + ")_" + doc.name);
		}
	}

	doc.fullName.copy(newDocFile.absoluteURI);
}