您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

BuildZMmp.wsf 2.6 KiB

54 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?xml version="1.0" encoding="windows-1251"?>
  2. <job>
  3. <runtime>
  4. <named name="target" helpstring=" , *.zmp" required="true" type="string"/>
  5. <example>Example: cscript BuildZMmp.wsf /target:"..\Maps"</example>
  6. </runtime>
  7. <script language="JScript">
  8. <![CDATA[
  9. function CBuildSource(Folder, Ext){
  10. this.Ext = Ext;
  11. this.fso = WScript.CreateObject("Scripting.FileSystemObject");
  12. this.Folder = this.fso.GetFolder(Folder);
  13. this.SourceCheckExtRegExp = new RegExp("^" + this.Ext + "$", "i");
  14. this.CheckExt = function(Folder){
  15. return this.fso.GetExtensionName(Folder.Name).match(this.SourceCheckExtRegExp);
  16. };
  17. this.GetSourceFoldersEnumerator = function(){
  18. return new Enumerator(this.Folder.SubFolders);
  19. };
  20. };
  21. function CBuilder(FolderName){
  22. this.fso = WScript.CreateObject("Scripting.FileSystemObject");
  23. this.WshShell = WScript.CreateObject("WScript.Shell");
  24. this.FolderExists = false;
  25. this.FolderName = FolderName;
  26. if (FolderName.length == 0){
  27. this.FolderName = ".";
  28. };
  29. this.GetNewFullFileName = function(FileName){
  30. if (!this.FolderExists){
  31. if (!this.fso.FolderExists(this.FolderName)){
  32. this.Folder = this.fso.CreateFolder(FolderName);
  33. this.FolderExists = true;
  34. }else{
  35. this.Folder = this.fso.GetFolder(this.FolderName);
  36. this.FolderExists = true;
  37. };
  38. };
  39. return this.fso.BuildPath(this.Folder.Path, this.fso.GetFileName(FileName));
  40. };
  41. this.GetCommandLine = function(SourceFolder, FileName){
  42. return "7za a -tzip \""+ FileName + "\" \"" + SourceFolder + "\\*.*\"" ;
  43. };
  44. this.ProcessFolder = function(Folder){
  45. var NewFileName = this.GetNewFullFileName(Folder.Name);
  46. var FolderFullName = Folder.Path;
  47. if (this.fso.FileExists(NewFileName)){
  48. this.fso.DeleteFile(NewFileName);
  49. };
  50. var CommandLine = this.GetCommandLine(FolderFullName, NewFileName);
  51. WScript.Echo(CommandLine);
  52. var Pipe = this.WshShell.Exec(CommandLine);
  53. while(!Pipe.StdOut.AtEndOfStream){
  54. WScript.StdOut.WriteLine(Pipe.StdOut.ReadLine());
  55. };
  56. }
  57. };
  58. if (!WScript.Arguments.Named.Exists("target")){
  59. WScript.Arguments.ShowUsage();
  60. }else{
  61. var Source = new CBuildSource(".", "zmp");
  62. var Builder = new CBuilder(WScript.Arguments.Named.Item("target"));
  63. var oFiles = Source.GetSourceFoldersEnumerator();
  64. for (; !oFiles.atEnd(); oFiles.moveNext()){
  65. var oFile = oFiles.item();
  66. if (Source.CheckExt(oFile)){
  67. Builder.ProcessFolder(oFile);
  68. };
  69. };
  70. };
  71. ]]>
  72. </script>
  73. </job>