home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2 (Special) / PCPro-2b.iso / Demos / Macromedia / CourseBuilder / CourseBuilderInstaller.exe / Disk1 / data1.cab / Dreamweaver-unInstalled / Configuration / Commands / Copying Files.js < prev    next >
Encoding:
JavaScript  |  1999-12-06  |  2.7 KB  |  90 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS  *****************
  4.  
  5. var COPYALL = false;
  6. var OVERWRITE = false;
  7.  
  8. var WAS_COPIED = false;
  9.  
  10. var IGNORE_LOCKED = false;
  11.  
  12.  
  13. //******************* API **********************
  14.  
  15. //***************** LOCAL FUNCTIONS  ******************
  16.  
  17. //Copies a directory and all subdirectories and files to another
  18. //  directory.  Args:
  19. //theSrcDirectory - the OS directory name to copy.
  20. //theTgtDirectory - the OS directory name to copy to.
  21. //
  22. function copyFileTree(theSrcDirectory, theTgtDirectory, dirOnly, overwrite) {
  23.   var iFile, iDir, fileList, dirList;
  24.   var source, target, fromFile, toFile;
  25.   var response;
  26.  
  27.   source = new File(theSrcDirectory);
  28.   target = new File(theTgtDirectory);
  29.   
  30.   // create the target folder
  31.   if (!target.exists()) target.mkdir();
  32.  
  33.   if (!dirOnly) {
  34.     // get a list of all the files in the source directory
  35.     fileList = source.list("*.*");
  36.  
  37.     // copy all the files from the source to target directory
  38.     fromFile = new File("");
  39.     toFile = new File("");
  40.     for (iFile=0; iFile < fileList.length; ++iFile) {
  41.       toFile.setPath(target.getAbsolutePath() + FILE_sep + fileList[iFile]);
  42.       fromFile.setPath(source.getAbsolutePath() + FILE_sep + fileList[iFile]);
  43.       if (!toFile.exists()) {
  44.         fromFile.copyTo(toFile.getAbsolutePath());
  45.       } else if (overwrite) {
  46.         if (toFile.remove())
  47.           fromFile.copyTo(toFile.getAbsolutePath());
  48.         else if (!IGNORE_LOCKED) {
  49.           response = confirmCustom(errMsg(MSG_cantRemoveFile, toFile.getAbsolutePath()),LABEL_yesAll, LABEL_yes, LABEL_cancel);
  50.           if (response == LABEL_yesAll)
  51.             IGNORE_LOCKED = true;
  52.           else if (response == LABEL_cancel)
  53.             return false;
  54.     } } }
  55.   }
  56.  
  57.   // get a list of all the directories in the source directory
  58.   dirList = source.list("*.*", "dirs");
  59.  
  60.   // create the target directory and copy the underlying tree
  61.   for (iDir=0; iDir < dirList.length; ++iDir) {
  62.     if (!copyFileTree(source.getAbsolutePath() + FILE_sep + dirList[iDir], 
  63.                       target.getAbsolutePath() + FILE_sep + dirList[iDir],
  64.                       dirOnly, overwrite)) 
  65.       return false;
  66.   }
  67.   return true;
  68. }
  69.  
  70.  
  71. function copyFiles() {
  72.   var theScripts = new File(PREF_scriptsUrl);
  73.   var theImages = new File(PREF_imagesUrl);
  74.   if (COPYALL) {
  75.     if (copyFileTree(FILE_scriptsUrl, PREF_scriptsUrl, false, true))
  76.       copyFileTree(FILE_imagesUrl, PREF_imagesUrl, false, OVERWRITE);
  77.   } else {
  78.     copyFileTree(FILE_scriptsUrl, PREF_scriptsUrl, false, true);
  79.   }
  80. }
  81.  
  82.  
  83. function initializeUI() {
  84.  
  85.   if (documentSaved(true))  
  86.     copyFiles();
  87.   garbageCollect(true);
  88.   window.close();
  89. }
  90.