Last active
March 27, 2016 16:50
-
-
Save DieterHolvoet/ea4e6a734ef0949a3e53 to your computer and use it in GitHub Desktop.
A series of File prototype functions for Adobe ExtendScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Return the corresponding Document object of a given File object, and open the file if necessary. */ | |
File.prototype.asDocument = function() { | |
var document = false; | |
for(var i = 0; i < app.documents.length; i++) { | |
if(app.documents[i].getFullPath() === this.getFullPath()) { | |
$.writeln("Found at index " + i + " => " + this.getFullPath()); | |
document = app.documents[i]; | |
break; | |
} | |
} | |
if(!document) { | |
app.open(this); | |
document = app.documents[0]; | |
} | |
return document; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Get file extension */ | |
File.prototype.getFileExtension = function() { | |
var str = this.fsName; | |
return str.substring(str.lastIndexOf(".") + 1); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Get file name */ | |
File.prototype.getFileName = function() { | |
var str = this.fsName; | |
return str.substring(str.lastIndexOf("\\") + 1, str.lastIndexOf(".")); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Get full path of file */ | |
File.prototype.getFullPath = function() { | |
return this.fsName; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Get full path of the folder containing the file */ | |
File.prototype.getFolderPath = function() { | |
var str = this.fsName; | |
return str.substring(0, str.lastIndexOf("\\")); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment