Copy link to clipboard
Copied
Hello fellow developers,
is there a way to discern whether a File is an alias on Mac? Like:
var fList = Folder("~/Desktop/TEMP").getFiles();
$.writeln(fList.toSource());
// [new File ("~/Desktop/TEMP/.DS_Store"), new File ("~/Desktop/TEMP/_Anita.jpg"), new File ("~/Desktop/TEMP/Anita.jpg")]
The TEMP folder contains (besides the hidden .DS_Store) a proper jpg called Anita.jpg and an alias which is _Anita.jpg.
On PC they have a .lnk extension, on Mac it gets harder to recognize them.
I thought to filter the getFile with somethig such as:
var fList = Folder("~/Desktop/TEMP").getFiles( function(f) {
//... if f is alias then return false
return true
});
Bu I don't know how to fill the function.
Any idea?
Thank you!
Davide Barranca
There is a File property for that. File.alias will be true if the file is an alias or shortcut.
Or are you saying that property doesn't work on Mac?
Copy link to clipboard
Copied
There is a File property for that. File.alias will be true if the file is an alias or shortcut.
Or are you saying that property doesn't work on Mac?
Copy link to clipboard
Copied
Yup Mike,
I did completely miss that property!
Works flawlessly, thanks!
var fList = Folder("~/Desktop/TEMP").getFiles( function(f) {
if (f.alias) { return false; }
return true;
});
Davide
www.davidebarranca.com
Copy link to clipboard
Copied
You could also do something like this.
var fList = Folder("~/Desktop/TEMP").getFiles( function(f) {
return !f.alias;
});
Copy link to clipboard
Copied
Speaking of aliases, do you happen to know how to copy them around "as aliases"?
Like:
var sourceFolder = Folder("~/Desktop/TEMP/Source");
var destFolder = Folder("~/Desktop/TEMP/Destination");
var fList = sourceFolder.getFiles();
for (var i = 0, len = fList.length; i < len; i++) {
fList.copy(destFolder + "/" + fList.name);
}
This one works, but copies the referenced files (instead of the aliases themselves)
Davide
Copy link to clipboard
Copied
you can recreate the alias
var sourceFolder = Folder("~/Desktop/TEMP/Source");
var destFolder = Folder("~/Desktop/TEMP/Destination");
var fList = sourceFolder.getFiles();
for (var i = 0, len = fList.length; i < len; i++) {
//fList.copy(destFolder + "/" + fList.name);
if (fList.alias) {
var destFile = new File(destFolder + "/" + fList.name);
destFile.createAlias (fList.fsName);
}
}