存档

文章标签 ‘批处理’

vbs对比更新删除

2010年7月3日 1 条评论

整理的是相当的痛苦。。。
更改这三条
echo copyfol “D:\”,”D:\b” >> c:\diff.
echo sdir=”d:\dnf” >> c:\diff.vbs
echo ddir=”d:\b” >> c:\diff.vbs

更改其中的这三条语句。
d:\dnf 为源目录。 d:\b 目的目录(需要更新还原的目录)。

  1. @echo off
  2. del /f /q  c:\diff.vbs
  3. echo Option Explicit >> c:\diff.vbs
  4.  
  5. echo sub copyfol(sDir,Ddir) >> c:\diff.vbs
  6.  
  7. echo   dim fso,fol,fs,f1, objfile >> c:\diff.vbs
  8. echo   dim arrFiles(),arrSize(),arrModified() >> c:\diff.vbs
  9. echo   dim i >>c:\diff.vbs
  10. echo   if right(ddir,1)^<^>"\" then ddir =ddir ^& "\" >> c:\diff.vbs
  11. echo   if right(sdir,1)^<^>"\" then sdir =sdir ^& "\" >> c:\diff.vbs
  12. echo   Set fso = CreateObject("Scripting.FileSystemObject") >> c:\diff.vbs
  13.  
  14. echo   if not (fso.FolderExists(sdir))  then >> c:\diff.vbs
  15. echo       msgbox "找不到文件夹:" ^& sdir >> c:\diff.vbs
  16. echo       exit sub >> c:\diff.vbs
  17. echo   end if >> c:\diff.vbs
  18. echo   if not (fso.FolderExists(ddir))  then >> c:\diff.vbs
  19. echo        msgbox "找不到文件夹:" ^& sdir >> c:\diff.vbs
  20. echo        exit sub >> c:\diff.vbs
  21. echo   end if >> c:\diff.vbs
  22.  
  23.  
  24. echo   set fol=fso.GetFolder(ddir) >> c:\diff.vbs
  25. echo   set fs=fol.files >> c:\diff.vbs
  26. echo   i=0 >> c:\diff.vbs
  27. echo   redim arrFiles(fs.count-1) >> c:\diff.vbs
  28. echo   redim arrSize(fs.count-1) >> c:\diff.vbs
  29. echo   redim arrModified(fs.count-1) >> c:\diff.vbs
  30. echo   for each f1 in fs >> c:\diff.vbs
  31. echo      arrfiles(i)=f1.name >> c:\diff.vbs
  32. echo      arrSize(i)=f1.size >> c:\diff.vbs
  33. echo      arrModified(i)=f1.DateLastModified >> c:\diff.vbs
  34. echo      i=i+1 >> c:\diff.vbs
  35. echo   next >> c:\diff.vbs
  36.  
  37. echo   set fol=fso.GetFolder(sdir) >> c:\diff.vbs
  38. echo   set fs=fol.files >> c:\diff.vbs
  39. echo   for i = 0 to ubound(arrfiles) >> c:\diff.vbs
  40.  
  41.  
  42. echo       dim delfile   >> c:\diff.vbs
  43. echo       delfile=false >> c:\diff.vbs
  44. echo       for each f1 in fs >> c:\diff.vbs
  45. echo           if strcomp(arrfiles(i),f1.name,vbTextCompare)=0 then     >> c:\diff.vbs         
  46. echo               if arrsize(i)^<^> f1.size or arrModified(i)^<^>f1.DateLastModified then >> c:\diff.vbs
  47. echo                  fso.copyfile f1.path, ddir ^& arrfiles(i),true        >> c:\diff.vbs
  48. echo               end if >> c:\diff.vbs
  49. echo              delfile=true '如果文件存在 >> c:\diff.vbs
  50. echo               exit for >> c:\diff.vbs
  51. echo            end if >> c:\diff.vbs
  52. echo        next >> c:\diff.vbs
  53. echo        if not delfile then      >> c:\diff.vbs             
  54. echo            set objfile=fso.getfile(ddir ^&arrfiles(i)) >> c:\diff.vbs
  55. echo            objfile.Delete (true) >> c:\diff.vbs
  56. echo         end if       >> c:\diff.vbs   
  57. echo    next >> c:\diff.vbs
  58.  
  59. echo   for each f1 in fs >> c:\diff.vbs
  60. echo       delfile=false >> c:\diff.vbs
  61. echo       for i=0 to ubound(arrfiles) >> c:\diff.vbs
  62. echo          if strcomp(f1.name,arrfiles(i),vbtextcompare)=0 then >> c:\diff.vbs
  63. echo             delfile=true >> c:\diff.vbs
  64. echo             exit for >> c:\diff.vbs
  65. echo          end if >> c:\diff.vbs
  66. echo        next  >> c:\diff.vbs
  67. echo         if right (ddir,1)^<^>"\" then ddir=ddir ^&"\" >> c:\diff.vbs
  68. echo        if not delfile then          >> c:\diff.vbs
  69. echo           f1.copy ddir,true >> c:\diff.vbs
  70. echo        end if >> c:\diff.vbs
  71. echo   next >> c:\diff.vbs
  72.  
  73. echo   dim fols >> c:\diff.vbs
  74. echo   set fol=Fso.GetFolder(sdir) >> c:\diff.vbs
  75. echo   set fols=fol.SubFolders >> c:\diff.vbs
  76. echo   for each f1 in fols >> c:\diff.vbs
  77. echo      if not (fso.FolderExists(ddir ^& f1.name)) then  >> c:\diff.vbs
  78. echo         fso.CreateFolder(ddir ^& f1.name) >> c:\diff.vbs
  79. echo      end if >> c:\diff.vbs
  80. echo      copyfol sdir ^& f1.name ,ddir ^& f1.name >> c:\diff.vbs
  81. echo   next >> c:\diff.vbs
  82. echo end sub >> c:\diff.vbs
  83.  
  84.  
  85. echo copyfol "D:\dnf","D:\b"  >> c:\diff.vbs
  86.  
  87. echo dim sdir,ddir  >> c:\diff.vbs
  88. echo '源目录  >> c:\diff.vbs
  89. echo sdir="d:\dnf"  >> c:\diff.vbs
  90. echo '目的目录  >> c:\diff.vbs
  91. echo ddir="d:\b"  >> c:\diff.vbs
  92. echo function comparefile(sdir,ddir)  >> c:\diff.vbs
  93. echo   dim Fso,dFol,dfs,sf1,f1  >> c:\diff.vbs
  94. echo   set Fso=CreateObject("Scripting.FileSystemObject")  >> c:\diff.vbs
  95. echo   if not(Fso.folderexists(sdir)) then  >> c:\diff.vbs
  96. echo       msgbox chr(34) ^&sdir ^&chr(34) ^&"文件夹不存在,请确认!",64  >> c:\diff.vbs
  97. echo       exit function  >> c:\diff.vbs
  98. echo   end if  >> c:\diff.vbs
  99. echo   if not(Fso.folderexists(ddir)) then  >> c:\diff.vbs
  100. echo       msgbox chr(34) ^&ddir ^&"""文件夹不存在,请确认!",64  >> c:\diff.vbs
  101. echo       exit function  >> c:\diff.vbs
  102. echo   end if  >> c:\diff.vbs
  103. echo   if right(sdir,1)^<^>"\" then sdir=sdir ^&"\"  >> c:\diff.vbs
  104. echo   set dFol=fso.getfolder(ddir)  >> c:\diff.vbs
  105. echo   set dfs=dfol.files  >> c:\diff.vbs
  106. echo   for each f1 in dfs  >> c:\diff.vbs
  107. echo       if fso.fileexists(sdir ^& f1.name)  then  >> c:\diff.vbs
  108. echo           set sf1=fso.GetFile(sdir ^& f1.name)  >> c:\diff.vbs
  109. echo           if f1.DateLastModified ^<^>sf1.DateLastModified or f1.size^<^>sf1.size then >> c:\diff.vbs
  110. echo               f1.delete  >> c:\diff.vbs
  111. echo           end if  >> c:\diff.vbs
  112. echo         else  >> c:\diff.vbs
  113. echo           f1.Delete(true)  >> c:\diff.vbs
  114. echo         end if  >> c:\diff.vbs
  115. echo     next  >> c:\diff.vbs
  116. echo   dim fols  >> c:\diff.vbs
  117. echo   set fols=dfol.subfolders  >> c:\diff.vbs
  118. echo   for each f1 in fols  >> c:\diff.vbs
  119. echo       if not fso.folderexists(sdir ^&f1.name) then  >> c:\diff.vbs
  120. echo             f1.delete true  >> c:\diff.vbs
  121. echo       else     >> c:\diff.vbs
  122. echo           comparefile sdir ^& f1.name,f1.path  >> c:\diff.vbs
  123. echo       end if  >> c:\diff.vbs
  124. echo   next  >> c:\diff.vbs
  125. echo end function  >> c:\diff.vbs
  126. echo comparefile sdir,ddir  >> c:\diff.vbs
  127.  
  128. start c:\diff.vbs

@echo off
del /f /q c:\diff.vbs
echo Option Explicit >> c:\diff.vbs

echo sub copyfol(sDir,Ddir) >> c:\diff.vbs

echo dim fso,fol,fs,f1, objfile >> c:\diff.vbs
echo dim arrFiles(),arrSize(),arrModified() >> c:\diff.vbs
echo dim i >>c:\diff.vbs
echo if right(ddir,1)^<^>“\” then ddir =ddir ^& “\” >> c:\diff.vbs
echo if right(sdir,1)^<^>“\” then sdir =sdir ^& “\” >> c:\diff.vbs
echo Set fso = CreateObject(“Scripting.FileSystemObject”) >> c:\diff.vbs

echo if not (fso.FolderExists(sdir)) then >> c:\diff.vbs
echo msgbox “找不到文件夹:” ^& sdir >> c:\diff.vbs
echo exit sub >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo if not (fso.FolderExists(ddir)) then >> c:\diff.vbs
echo msgbox “找不到文件夹:” ^& sdir >> c:\diff.vbs
echo exit sub >> c:\diff.vbs
echo end if >> c:\diff.vbs

echo set fol=fso.GetFolder(ddir) >> c:\diff.vbs
echo set fs=fol.files >> c:\diff.vbs
echo i=0 >> c:\diff.vbs
echo redim arrFiles(fs.count-1) >> c:\diff.vbs
echo redim arrSize(fs.count-1) >> c:\diff.vbs
echo redim arrModified(fs.count-1) >> c:\diff.vbs
echo for each f1 in fs >> c:\diff.vbs
echo arrfiles(i)=f1.name >> c:\diff.vbs
echo arrSize(i)=f1.size >> c:\diff.vbs
echo arrModified(i)=f1.DateLastModified >> c:\diff.vbs
echo i=i+1 >> c:\diff.vbs
echo next >> c:\diff.vbs

echo set fol=fso.GetFolder(sdir) >> c:\diff.vbs
echo set fs=fol.files >> c:\diff.vbs
echo for i = 0 to ubound(arrfiles) >> c:\diff.vbs

echo dim delfile >> c:\diff.vbs
echo delfile=false >> c:\diff.vbs
echo for each f1 in fs >> c:\diff.vbs
echo if strcomp(arrfiles(i),f1.name,vbTextCompare)=0 then >> c:\diff.vbs
echo if arrsize(i)^<^> f1.size or arrModified(i)^<^>f1.DateLastModified then >> c:\diff.vbs
echo fso.copyfile f1.path, ddir ^& arrfiles(i),true >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo delfile=true ‘如果文件存在 >> c:\diff.vbs
echo exit for >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo next >> c:\diff.vbs
echo if not delfile then >> c:\diff.vbs
echo set objfile=fso.getfile(ddir ^&arrfiles(i)) >> c:\diff.vbs
echo objfile.Delete (true) >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo next >> c:\diff.vbs

echo for each f1 in fs >> c:\diff.vbs
echo delfile=false >> c:\diff.vbs
echo for i=0 to ubound(arrfiles) >> c:\diff.vbs
echo if strcomp(f1.name,arrfiles(i),vbtextcompare)=0 then >> c:\diff.vbs
echo delfile=true >> c:\diff.vbs
echo exit for >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo next >> c:\diff.vbs
echo if right (ddir,1)^<^>“\” then ddir=ddir ^&”\” >> c:\diff.vbs
echo if not delfile then >> c:\diff.vbs
echo f1.copy ddir,true >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo next >> c:\diff.vbs

echo dim fols >> c:\diff.vbs
echo set fol=Fso.GetFolder(sdir) >> c:\diff.vbs
echo set fols=fol.SubFolders >> c:\diff.vbs
echo for each f1 in fols >> c:\diff.vbs
echo if not (fso.FolderExists(ddir ^& f1.name)) then >> c:\diff.vbs
echo fso.CreateFolder(ddir ^& f1.name) >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo copyfol sdir ^& f1.name ,ddir ^& f1.name >> c:\diff.vbs
echo next >> c:\diff.vbs
echo end sub >> c:\diff.vbs

echo copyfol “D:\dnf”,”D:\b” >> c:\diff.vbs

echo dim sdir,ddir >> c:\diff.vbs
echo ‘源目录 >> c:\diff.vbs
echo sdir=”d:\dnf” >> c:\diff.vbs
echo ‘目的目录 >> c:\diff.vbs
echo ddir=”d:\b” >> c:\diff.vbs
echo function comparefile(sdir,ddir) >> c:\diff.vbs
echo dim Fso,dFol,dfs,sf1,f1 >> c:\diff.vbs
echo set Fso=CreateObject(“Scripting.FileSystemObject”) >> c:\diff.vbs
echo if not(Fso.folderexists(sdir)) then >> c:\diff.vbs
echo msgbox chr(34) ^&sdir ^&chr(34) ^&”文件夹不存在,请确认!”,64 >> c:\diff.vbs
echo exit function >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo if not(Fso.folderexists(ddir)) then >> c:\diff.vbs
echo msgbox chr(34) ^&ddir ^&”"”文件夹不存在,请确认!”,64 >> c:\diff.vbs
echo exit function >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo if right(sdir,1)^<^>“\” then sdir=sdir ^&”\” >> c:\diff.vbs
echo set dFol=fso.getfolder(ddir) >> c:\diff.vbs
echo set dfs=dfol.files >> c:\diff.vbs
echo for each f1 in dfs >> c:\diff.vbs
echo if fso.fileexists(sdir ^& f1.name) then >> c:\diff.vbs
echo set sf1=fso.GetFile(sdir ^& f1.name) >> c:\diff.vbs
echo if f1.DateLastModified ^<^>sf1.DateLastModified or >> c:\diff.vbs

f1.size^<^>sf1.size echo then >> c:\diff.vbs
echo f1.delete >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo else >> c:\diff.vbs
echo f1.Delete(true) >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo next >> c:\diff.vbs
echo dim fols >> c:\diff.vbs
echo set fols=dfol.subfolders >> c:\diff.vbs
echo for each f1 in fols >> c:\diff.vbs
echo if not fso.folderexists(sdir ^&f1.name) then >> c:\diff.vbs
echo f1.delete true >> c:\diff.vbs
echo else >> c:\diff.vbs
echo comparefile sdir ^& f1.name,f1.path >> c:\diff.vbs
echo end if >> c:\diff.vbs
echo next >> c:\diff.vbs
echo end function >> c:\diff.vbs
echo comparefile sdir,ddir >> c:\diff.vbs

对比更新 vbs

2010年3月26日 没有评论
  1. Option Explicit
  2.  
  3. sub copyfol(sDir,Ddir)
  4.  'sDiry要对比的文件夹,,Ddir要操作文件夹
  5.    dim fso,fol,fs,f1, objfile
  6.    dim arrFiles(),arrSize(),arrModified()
  7.    dim i
  8.    if right(ddir,1)<>"\" then ddir =ddir & "\"
  9.    if right(sdir,1)<>"\" then sdir =sdir & "\"
  10.    Set fso = CreateObject("Scripting.FileSystemObject")
  11.    '判断文件是否存在
  12.    if not (fso.FolderExists(sdir))  then
  13.        msgbox "找不到文件夹:" & sdir
  14.        exit sub
  15.    end if
  16.    if not (fso.FolderExists(ddir))  then
  17.         msgbox "找不到文件夹:" & sdir
  18.         exit sub
  19.    end if
  20.  
  21.    '获得要操作的文件列表及相关信息并储存到数组
  22.    set fol=fso.GetFolder(ddir)
  23.    set fs=fol.files
  24.    i=0
  25.    redim arrFiles(fs.count-1)
  26.    redim arrSize(fs.count-1)
  27.    redim arrModified(fs.count-1)
  28.    for each f1 in fs
  29.       arrfiles(i)=f1.name
  30.       arrSize(i)=f1.size
  31.       arrModified(i)=f1.DateLastModified
  32.       i=i+1
  33.    next
  34.    '把要操作的文件夹逐一根要对比的文件比较,不同则覆盖,多余就删除,没有就复制
  35.    set fol=fso.GetFolder(sdir)
  36.    set fs=fol.files
  37.    for i = 0 to ubound(arrfiles)
  38.        '文件存在则比较是否相同,否则删除
  39.  
  40.        dim delfile  '要操作类型,
  41.        delfile=false
  42.        for each f1 in fs
  43.            if strcomp(arrfiles(i),f1.name,vbTextCompare)=0 then             
  44.                if arrsize(i)<> f1.size or arrModified(i)<>f1.DateLastModified then
  45.                   fso.copyfile f1.path, ddir & arrfiles(i),true       
  46.                end if
  47.                delfile=true '如果文件存在
  48.                exit for
  49.             end if
  50.         next
  51.         if not delfile then                 
  52.             set objfile=fso.getfile(ddir &arrfiles(i))
  53.             objfile.Delete (true)
  54.          end if         
  55.     next
  56.    '如果对比目录sdir中有文件是要操作目录ddir中没有的,则复制到ddir
  57.    for each f1 in fs
  58.        delfile=false
  59.        for i=0 to ubound(arrfiles)
  60.           if strcomp(f1.name,arrfiles(i),vbtextcompare)=0 then
  61.              delfile=true
  62.              exit for
  63.           end if
  64.         next
  65.          if right (ddir,1)<>"\" then ddir=ddir &"\"
  66.         if not delfile then         
  67.            f1.copy ddir,true
  68.         end if
  69.    next
  70.    '以下代码处理子文件夹 
  71.    dim fols
  72.    set fol=Fso.GetFolder(sdir)
  73.    set fols=fol.SubFolders
  74.    for each f1 in fols
  75.       if not (fso.FolderExists(ddir & f1.name)) then
  76.          fso.CreateFolder(ddir & f1.name)
  77.       end if
  78.       copyfol sdir & f1.name ,ddir & f1.name
  79.    next
  80. end sub
  81.  
  82.    '以下是对比路径 第一个是远程路径 第二个是本地路径
  83. copyfol "c:\viyin.net","C:\www.viyin.net"

dnf

2010年3月16日 没有评论

@echo off
type D:\1\_CHINA.CFG | find /i “NOTIFYING_MINIMAP=1″ &&echo on &&goto run

for /l %%a in (1,1,10) do (

type D:\DNF1\DNF_CHINA.CFG | find /i “NOTIFYING_MINIMAP=1″ &&echo on &&goto run

ping 127.1 -n 2 >nul

)

exit

:run
@echo off

for /f “delims=” %%i in (‘dir /b/s/a-d “D:\DNF1\DNF_CHINA.CFG”‘) do (
findstr /v “[CH” “%%i” >”%%~dpni.new”
del /q “%%i”
ren “%%~dpni.new” “%%~ni.CFG”
)

for /f “delims=” %%i in (‘dir /b/s/a-d “D:\DNF1\DNF_CHINA.CFG”‘) do (
findstr /v “NOTIFYING_” “%%i” >”%%~dpni.new”
del /q “%%i”
ren “%%~dpni.new” “%%~ni.CFG”
)

exit

批处理删除指定行

2010年3月1日 没有评论

批处理删除指定行

@echo off
for /f “delims=” %%i in (‘dir /b/s/a-d “C:\文件路径”‘) do (
findstr /v “要指定删除行包含的字符” “%%i” >”%%~dpni.new”
del /q “%%i”
ren “%%~dpni.new” “%%~ni.ini”
)

替换文本中的字符

2010年2月6日 没有评论

echo Set fso = Wscript.CreateObject(“Scripting.FileSystemObject”)>c:\viyin.
echo set f=fso.opentextfile(“D:\1\_CHINA.CFG”)>>c:\viyin.vbs
echo s=replace(f.readall,”MUSIC VOLUME=100″,”MUSIC VOLUME=0″)>>c:\viyin.vbs
echo f.close>>c:\viyin.vbs
echo set   r=fso.opentextfile(“D:\DNF1\DNF_CHINA.CFG”,2,true)>>c:\viyin.vbs
echo r.write  s>>c:\viyin.vbs
echo Wscript.quit>>c:\viyin.vbs
start c:\viyin.vbs
echo Set fso = Wscript.CreateObject(“Scripting.FileSystemObject”)>c:\viyin.vbs
echo set f=fso.opentextfile(“D:\DNF1\DNF_CHINA.CFG”)>>c:\viyin.vbs
echo s=replace(f.readall,”SOUND VOLUME=100″,”SOUND VOLUME=0″)>>c:\viyin.vbs
echo f.close>>c:\viyin.vbs
echo set   r=fso.opentextfile(“D:\DNF1\DNF_CHINA.CFG”,2,true)>>c:\viyin.vbs
echo r.write  s>>c:\viyin.vbs
echo Wscript.quit>>c:\viyin.vbs
start c:\viyin.vbs