Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Thanked 0 Times in 0 Posts

    Unhappy Copy files using File System Object (VBScript)

    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.

    		<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");
    					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.
    					//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.
    						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;
    						//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.
    							//check if destination file exists
    								//check if the destination file exists.
    									//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.
    										//change the fill attribute to 0.
    										//.....put your code here for changing the file attribute.
    										alert("File doesn't need copying");
    								alert("File doesn't exist please copy the files");
    						alert(sourceFileName + "-" + destFileName);	
    						//move enumerator to the next object.
    					//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.
    										//create a folder and copy all files.
    										//proceed with copying all files.
    										alert("Folder has been copied");
    										//Otherwise display a error message.
    										alert("The source folder (FROM: ) doesn't exist" + "check your entry and try again");
    	<BODY bgcolor="brightred">
    			<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

  2. AdSlot6
  3. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,945 Times in 4,906 Posts
    Why did you say "VBScript" when clearly all of that code is in JavaScript?

    I do hope you know this code will only work:
    (a) in MSIE
    (b) if the user has marked your site as a "trusted" site (or if it is run locally, of course)
    (c) if the user allows the script to run after getting a message that the code is marked as "unsafe for scripting".

    Anyway, all that code is horribly clumsy and ugly. And it really would be easier for me to throw it away and code it in VBScript. Since this will only work in MSIE, why not use VBScript?
    Be yourself. No one else is as qualified.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts