Thanks Mark,
Actually my task is copy the file and paste it in a destination folder, but the thing is it should not modify the date of creation.
While doing copy paste in javascript it modifies the current date to that file. It should not happen to my case.
Plz help me.
Thanks in Advance
Actually my task is copy the file and paste it in a destination folder, but the thing is it should not modify the date of creation. While doing copy paste in javascript it modifies the current date to that file. It should not happen to my case. |
It's a little bit late to answer -- two weeks have already passed -- but here is a function that I wrote to deal with this problem, it works both for Mac and Windows.
Kasyan
function MoveFile(myFile, myFolder) {
if (!myFile instanceof File || !myFolder instanceof Folder || !myFile.exists || !myFolder.exists) return false;
var myMovedFile = new File(myFolder.absoluteURI + "/" + myFile.name);
if (File.fs == "Windows") {
var myVbScript = 'Set fs = CreateObject("Scripting.FileSystemObject")\r';
myVbScript += 'fs.MoveFile "' + myFile.fsName + '", "' + myFolder.fsName + '\\"';
app.doScript(myVbScript, ScriptLanguage.visualBasic);
}
else if (File.fs == "Macintosh") {
if (myFolder.fsName.match("Desktop") != null) {
var myMacFolder = myFolder.fsName.replace(/\//g, ":");
var myMacFile = myFile.fsName.replace(/\//g, ":");
var myAppleScript = 'tell application "Finder"\r';
myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';
myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';
myAppleScript += 'tell myFile\r';
myAppleScript += 'move to myFolder\r';
myAppleScript += 'end tell\r';
myAppleScript += 'end tell\r';
}
else if (myFolder.fsName.match("Documents") != null) {
var myMacFolder = myFolder.fsName.replace(/\//g, ":");
var myMacFile = myFile.fsName.replace(/\//g, ":");
var myAppleScript = 'tell application "Finder"\r';
myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';
myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';
myAppleScript += 'tell myFile\r';
myAppleScript += 'move to myFolder\r';
myAppleScript += 'end tell\r';
myAppleScript += 'end tell\r';
}
else {
var myMacFolder = myFolder.fullName.replace(/\//, "").replace(/\//g, ":");
var myMacFile = myFile.fullName.replace(/\//, "").replace(/\//g, ":");
var myAppleScript = 'tell application "Finder"\r';
myAppleScript += 'set myFolder to folder "' + myMacFolder + '"\r';
myAppleScript += 'set myFile to document file "' + myMacFile + '"\r';
myAppleScript += 'tell myFile\r';
myAppleScript += 'move to myFolder\r';
myAppleScript += 'end tell\r';
myAppleScript += 'end tell\r';
}
app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);
}
if (myMovedFile.exists) {
return true;
}
else {
return false;
}
}