2012-10-03 20 views
6

मैं एक स्क्रिप्ट विंडोज की क्षमताओं में बनाया गया एक आपूर्ति .zip फ़ाइल अनज़िप करने के लिए उपयोग करेंगे उस पर काम कर रहा हूँ। मैं vbscript के लिए बहुत नया हूँ इसलिए कुछ वाक्यविन्यास मुझे थोड़ा स्टंप करता है। मैं कुछ मौजूदा कोड के साथ काम कर रहा हूं और इसे संशोधित करने की कोशिश कर रहा हूं ताकि यह फ़ाइल नाम के लिए कमांड लाइन विकल्प ले सके। अगर मैं कमांड लाइन का उपयोग फ़ाइल नाम पारित करने के लिए, मैं त्रुटि प्राप्त:कमांड लाइन तर्क - आवश्यक वस्तु: 'objshell.NameSpace (...)'

object required: 'objshell.NameSpace(...)'

अगर मैं स्क्रिप्ट में पाठ के साथ एक ही चर पॉप्युलेट, स्क्रिप्ट त्रुटि मुक्त चलाता है। क्या कमांड तर्कों का उपयोग करने का प्रयास करते समय मुझे कोई अन्य टुकड़ा याद आ रहा है?

Option Explicit 

Dim sDestinationDirectory,sLogDestination,fso,outLog,sJunk,sSourceFile 

sDestinationDirectory = "C:\scripts\vbscriptTemplates\unzip" 
sLogDestination = "C:\scripts\vbscriptTemplates\" 

Set fso=CreateObject("Scripting.FileSystemObject") 
Set outLog = fso.OpenTextFile("unzipRIP.log", 2, True) 
If WScript.Arguments.Count = 1 Then 
    sSourceFile = WScript.Arguments.Item(0)  'Using this line the code will fail. 
    'sSourceFile = "C:\scripts\vbscriptTemplates\test.zip"  'Using this line the code will run. 
    outLog.WriteLine ".:|Processing new zip file|:." 
    outLog.WriteLine "Processing file: " & sSourceFile 
    Extract sSourceFile,sDestinationDirectory 
Else 
    sJunk = MsgBox("File to be processed could not be found. Please verify.",0,"Unzip - File not found") 
    outLog.WriteLine "File to be processed could not be found. Please verify." 
    outLog.Close 
    Wscript.Quit 
End If 

Sub Extract(ByVal myZipFile, ByVal myTargetDir) 
    Dim intOptions, objShell, objSource, objTarget 

    outLog.WriteLine "Processing file in subroutine: " & myZipFile & " target " & myTargetDir 
    ' Create the required Shell objects 
    Set objShell = CreateObject("Shell.Application") 

    ' Create a reference to the files and folders in the ZIP file 
    Set objSource = objShell.NameSpace(myZipFile).Items() 

    ' Create a reference to the target folder 
    Set objTarget = objShell.NameSpace(myTargetDir) 
    intOptions = 4 

    ' UnZIP the files 
    objTarget.CopyHere objSource, intOptions 

    ' Release the objects 
    Set objSource = Nothing 
    Set objTarget = Nothing 
    Set objShell = Nothing 
End Sub 

लाइन संदर्भित

sSourceFile = WScript.Arguments.Item(0)

है यह रोब वान डर Woude द्वारा लिखे कोड पर एक बदलाव बनाने के लिए मेरे प्रयास है:

यहाँ मेरी कोड है। http://www.robvanderwoude.com/vbstech_files_zip.php#CopyHereUNZIP

उत्तर

12

Set fso = CreateObject("Scripting.FileSystemObject") 
sSourceFile = fso.GetAbsolutePathName(WScript.Arguments.Item(0)) 

बजाय

sSourceFile = WScript.Arguments.Item(0) 
+0

यह एक विजेता की तरह काम किया की कोशिश करो। तो मैं बेहतर समझ सकता हूं, इस मामले में फ़ाइल के पूर्ण पथ का उपयोग करने से पहले मैं क्या उपयोग कर रहा था उससे बेहतर काम करता हूं? मुझे लगता है कि मैं पहले एक सापेक्ष पथ का उपयोग कर रहा था? या मेरी स्क्रिप्ट ने मुझे किसी अन्य निर्देशिका में फ़ाइल को देखने का प्रयास किया है? सहायता के लिए धन्यवाद! – gritts

+0

मुझे संदेह है कि आप पहले एक सापेक्ष स्रोत पथ का उपयोग कर रहे थे। –

संबंधित मुद्दे