2016-06-23 2 views
1

파일을 검색하고 복사 한 다음 압축하는 배치 파일이 있습니다. 문제 영역은 끝에 배치 파일 내에서 vbs 파일을 만든 다음 실행합니다.필요한 개체 : 'objShell.NameSpace (...)'Sompin '이 올바르지 않습니다.

@echo off 

setlocal enabledelayedexpansion 

REM ** Loops through each arugment in the input file 

set fileList=sys-conf.txt, CNCIDNUM.txt, cnc-para.txt,pitch.txt,OPRT_HIS.txt,TOOLOFST.TXT,macro.txt,3D-INTER.txt,ATCMagazine_,Makino_AtdAxis_CMN_,Makino_AtdAxis_Duty_,Makino_Atdspindle_,Makino_IOlink_setting,Makino_MMS_,Makino_Parameter_,Makino_QAC_CurveFit_,Makino_QAC_Override_,Makino_QAC_Setting_,PalletMagazine_,MCA_selectData.txt 

:getDestination 
set /p destination=Enter the destination Folder to copy the files : 
if not exist !destination! goto getDestination 

for %%A in ("%~f0\..") do set "fol=%%~nxA" 

set m_dd=%date%_%time% 
set m_dd=%m_dd: =% 
set m_dd=%m_dd::=_% 
set m_dd=%m_dd:/=_% 
set m_dd=%m_dd:.=_% 
set m_d=%m_dd:~3,-3% 

set dest=!destination!\%fol%_%m_d% 
set op=%dest%.zip 

if not exist !dest! (
    echo !dest! 
    mkdir !dest! 
) else (
    :getConfirm 
    set _confirm=Folder Already Exists..Continue [Y/N] : 
    if /i "!_confirm!"=="n" (
    timeout /t 3 
    echo "Script Execution Terminated" 
    exit 
    ) 
    if /i not "!_confirm!"=="n" if /i not "!_confirm!"=="y" (
    goto getConfirm 
    ) 
) 

for %%F in (%fileList%) do (
echo Checking for the file...: %%F 

REM ** Check whether the file is present in the directory --> Find command is used for handling "No files found" 
for /f %%H in ('dir /s /b *%%F* 2^>nul ^| find /C /V ""') do (

REM ** If No files are found ask user confirmation 
if %%H==0 (
:input 
set /p confirm=File Not Found..Do you want to continue [Y/N] : 

if /i "!confirm!"=="y" (
for /f %%B in ('dir /s /b *%%F*') do (
echo File Found: %%B 
copy %%B "!dest!" 
) 
) 
if /i "!confirm!"=="n" (
timeout /t 7 
echo "Script Execution terminated" 
exit 
) 
if /i not "!confirm!"=="n" if /i not "!confirm!"=="y" (
goto input 
) 

) else (
REM ** If files are found copy them to the destination 
for /f %%B in ('dir /s /b *%%F*') do (
echo File Found: %%B 
copy %%B "!dest!" 
) 
) 
) 
) 
@echo off>zip.vbs 
@echo 'Get command-line arguments.>>zip.vbs 
@echo Set objArgs = WScript.Arguments>>zip.vbs 
@echo InputFolder = objArgs(0)>>zip.vbs 
@echo ZipFile = objArgs(1)>>zip.vbs 
@echo REM>>zip.vbs 
@echo 'Create empty ZIP file.>>zip.vbs 
@echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar)>>zip.vbs 
@echo REM>>zip.vbs 
@echo Set objShell = CreateObject("Shell.Application")>>zip.vbs 
@echo REM>>zip.vbs 
@echo Set source = objShell.NameSpace(InputFolder).Items>>zip.vbs 
@echo REM>>zip.vbs 
@echo objShell.NameSpace(ZipFile).CopyHere(source)>>zip.vbs 
@echo REM>>zip.vbs 
@echo 'Required!>>zip.vbs 
@echo wScript.Sleep 2000>>zip.vbs 
CScript zip.vbs !dest! .\success.zip 

오류 출력은 이것이다 : 여기에 내 코드입니다! "의! 이명 령"

E:\somefolder\zip.vbs(11, 1) Microsoft VBScript runtime e 
rror: Object required: 'objShell.NameSpace(...)' 

내 와 ". \ success.zip"은 순전히 추측이며 두 번째 대답은 this question에 대한 코드의 마지막 부분입니다.

이상적으로 나는 현재 디렉토리가 무엇이든 상관없이 zip 파일을 갖고 싶습니다. 그리고 나는 zip 파일 이름이 무엇인지 신경 쓰지 않습니다.

답변

0

다음은 실제로 작동합니다.

@echo off 

setlocal enabledelayedexpansion 

REM ** Loops through each arugment in the input file 

set fileList=data 

:getDestination 
set /p destination=Enter the destination Folder to copy the files : 
if not exist !destination! goto getDestination 

for %%A in ("%~f0\..") do set "fol=%%~nxA" 

set m_dd=%date%_%time% 
set m_dd=%m_dd: =% 
set m_dd=%m_dd::=_% 
set m_dd=%m_dd:/=_% 
set m_dd=%m_dd:.=_% 
set m_d=%m_dd:~3,-3% 

set dest=!destination!\%fol%_%m_d% 
set op=%dest%.zip 

if not exist !dest! (
    mkdir !dest! 
) else (
    :getConfirm 
    set _confirm=Folder Already Exists..Continue [Y/N] : 
    if /i "!_confirm!"=="n" (
    timeout /t 3 
    echo "Script Execution Terminated" 
    exit 
    ) 
    if /i not "!_confirm!"=="n" if /i not "!_confirm!"=="y" (
    goto getConfirm 
    ) 
) 

for %%F in (%fileList%) do (
echo Checking for the file...: %%F 

REM ** Check whether the file is present in the directory --> Find command is used for handling "No files found" 
for /f %%H in ('dir /s /b *%%F* 2^>nul ^| find /C /V ""') do (

REM ** If No files are found ask user confirmation 
if %%H==0 (
:input 
set /p confirm=File Not Found..Do you want to continue [Y/N] : 

if /i "!confirm!"=="y" (
for /f %%B in ('dir /s /b *%%F*') do (
echo File Found: %%B 
copy %%B "!dest!" 
) 
) 
if /i "!confirm!"=="n" (
timeout /t 7 
echo "Script Execution terminated" 
exit 
) 
if /i not "!confirm!"=="n" if /i not "!confirm!"=="y" (
goto input 
) 

) else (
REM ** If files are found copy them to the destination 
for /f %%B in ('dir /s /b *%%F*') do (
echo File Found: %%B 
copy %%B "!dest!" 
) 
) 
) 
call :zippy !dest! 

) 

:zippy 
echo InputFolder = WScript.Arguments.Item(0)>zip.vbs 
echo zipFileName = WScript.Arguments.Item(1)>>zip.vbs 
echo With CreateObject("Scripting.FileSystemObject")>>zip.vbs 
echo zipFile = .GetAbsolutePathName(zipFileName)>>zip.vbs 
echo sourceFolder = .GetAbsolutePathName(InputFolder)>>zip.vbs 
echo With .CreateTextFile(zipFile, True)>>zip.vbs 
echo .Write Chr(80) ^& Chr(75) ^& Chr(5) ^& Chr(6) ^& String(18, chr(0))>>zip.vbs 
echo End With>>zip.vbs 
echo End With>>zip.vbs 
echo With CreateObject("Shell.Application")>>zip.vbs 
echo .NameSpace(zipFile).CopyHere .NameSpace(sourceFolder).Items>>zip.vbs 
echo Do Until .NameSpace(zipFile).Items.Count = _>>zip.vbs 
echo .NameSpace(sourceFolder).Items.Count>>zip.vbs 
echo WScript.Sleep 10000>>zip.vbs 
echo Loop>>zip.vbs 
echo End With>>zip.vbs 
CScript zip.vbs "%1" .\success.zip 
관련 문제