The code below is what I already have and I just need someone to add the rest.
I require this program to copy multiply files in folders on F: and C: to either F: or C: based on last modified date and rename the old ones with "_old" at the end of the file names.
Please I need this done.
Cheers
Adrian1995
Code:
<HTML>
<HEAD>
<TITLE>Copy Project Files</TITLE>
<SCRIPT language="JavaScript">
<!--
//Call function here
//this function will check if the given folder is exists.
function checkExistingFolder(Project)
{
var fs = new ActiveXObject("Scripting.FileSystemObject");
return fs.FolderExists(Project);
}
//this function will create a folder and display a message.
function createFolder(Project)
{
var fs = new ActiveXObject("Scripting.FileSystemObject");
fs.CreateFolder(Project);
document.write("New folder created.");
}
//this function will copy the file from the source to the destination.
function copyFile(sourceFile, destFile)
{
var fs = new ActiveXObject("Scripting.FileSystemObject");
fs.copyFile(sourceFile, destFile);
document.write(sourceFile + " has been transferred! <br>");
alert(sourceFile + "Has been transferred<BR>");
}
//this function will rename the file with _old at the end.
function rename()
{
var new file name;
new file name = destination + getbasename(getfile.(destinationfile).name)
+ "_old"
copyFile(destinationfile, new file name);
}
function loopThroughFiles(source,dest)
{
var fs = new ActiveXObject("Scripting.FileSystemObject");
//get the file system folder object - source.
var sourceFolder = fs.GetFolder(source);
//get the file system folder object - destination.
var destFolder = fs.GetFolder(dest);
//get the file collection of the file system folder object.\
var fileCollection = sourceFolder.Files;
//enumerate file collections.
var objEnum = new Enumerator(fileCollection);
//move enumerator to the first item of the collection.
objEnum.moveFirst();
//declare a filename variable to hold the item in the enumerator.
var sourceFileName;
var destFileName;
var sourceFileDate;
var destFileDate;
//loop through each file in the enumerator.
while(!objEnum.atEnd())
{
alert (source);
sourceFileName = objEnum.item();
sourceFileDate = new Date(sourceFileName.DateLastModified);
//create the destination file name by concatenating the detsination path
//with the file name from the source file.
destFileName = dest + "\\" + sourceFileName.Name;
alert(sourceFileDate);
//display the name of the file
//document.write("<BR>" + fileName.Name);
//document.write("<BR>" + new Date(fileName.DateLastModified).toDateString());
//check if the file has been modified, 32 means has been modified.
if(sourceFileName.Attributes==32)
{
//check if destination file exists
if(fs.FileExists(destFileName))
{
alert("yes");
//check if the destination file exists.
if(fs.FileExists(destFileName))
{
//get the date last modified of the destination.
destFileDate = new Date(sourceFileName.DateLastModified).toDateString();
//if the last date modified of the source is greater then
//destination last date modified.
if(sourceFileDate > destFileDate)
{
//rename the destination file by appending "_old"
//.....put your code here for renaming file.
//copy the file from the source to the destination.
copyFile(sourceFileName,destFileName);
//change the fill attribute to 0.
//.....put your code here for changing the file attribute.
}
else
{
alert("File doesn't need copying");
}
}
else
{
alert("File doesn't exist please copy the files");
}
}
alert(sourceFileName + "-" + destFileName);
//move enumerator to the next object.
objEnum.moveNext();
}
}
//this function is the start of the program.
function runProgram()
{
var fs = new ActiveXObject("Scripting.FileSystemObject");
//to get the value of the source folder textbox.
var sourcePath = document.getElementById("from").value;
//to get the value of the destination folder textbox.
var destPath = document.getElementById("to").value;
//Check if source folder exists.
var sourceFolderExists = checkExistingFolder(sourcePath);
//Check if destination folder exists.
var destFolderExists = checkExistingFolder(destPath);
//if source folder exists.
if (sourceFolderExists)
{
//continue with the process below.
//if destination folder exists.
if (destFolderExists)
{
//get the file collections.
loopThroughFiles(sourcePath,destPath);
}
else
{
//create a folder and copy all files.
//proceed with copying all files.
fs.CopyFolder(sourcePath,destPath);
alert("Folder has been copied");
}
}
else
{
//Otherwise display a error message.
alert("The source folder (FROM: ) doesn't exist" + "check your entry and try again");
}
}
//-->
</SCRIPT>
</HEAD>
<BODY bgcolor="brightred">
<CENTER>
<H1>Copy Project Files</H1>
FROM: <input type="text" id="from" value="F:\\Project" />
TO: <input type="text" id="to" value="D:\\Project"/>
<input type="button" onclick="runProgram()" value="Transfer Project Files" />
<SCRIPT language="JavaScript">
<!--
//Call function here
//-->
</SCRIPT>
</CENTER>
</BODY>
</HTML>