TanjimReza Posted December 27, 2019 Share Posted December 27, 2019 I'm adding a Zip file named 'BATMAN.zip' in my script. FileInstall("C:\Users\tanji\OneDrive\Desktop\BATMAN.zip", @ScriptDir & "\BATMAN.zip") Then exctracting it. Const $sZipFile = @ScriptDir & "\BATMAN.zip" Const $sDestFolder = @ScriptDir UnZip($sZipFile, $sDestFolder) If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error unzipping file : " & @error) Func UnZip($sZipFile, $sDestFolder) If Not FileExists($sZipFile) Then Return SetError (1) ; source file does not exists If Not FileExists($sDestFolder) Then If Not DirCreate($sDestFolder) Then Return SetError (2) ; unable to create destination Else If Not StringInStr(FileGetAttrib($sDestFolder), "D") Then Return SetError (3) ; destination not folder EndIf Local $oShell = ObjCreate("shell.application") Local $oZip = $oShell.NameSpace($sZipFile) Local $iZipFileCount = $oZip.items.Count If Not $iZipFileCount Then Return SetError (4) ; zip file empty For $oFile In $oZip.items $oShell.NameSpace($sDestFolder).copyhere($ofile) Next EndFunc ;==>UnZip When extracted 'BATMAN.zip' it becomes -> Folder1\script.cmd. And I want to delete 'BATMAN.zip' and 'Folder1' and it's contents once my 'script.cmd' stops/closes running. To do that I'm adding Local $FilePath = @ScriptDir & "\BATMAN" Local $DEL = @ScriptDir & "\BATMAN.zip" Local $sFilePath = @ScriptDir & "\Folder1" RunWait(@ScriptDir & "\Folder1\script.cmd","", @SW_HIDE) Local $DeleteDEL = FileDelete($DEL) Local $DELME = DirRemove($sFilePath, $DIR_REMOVE) I've added these code to do this but my code deletes those contents before it's being run. So my script doesn't run, it shows can't find the file. Even though I'm using RunWait/ShellExecuteWait, but it doesn't work. Folder gets deleted before the script inside it runs. Link to comment Share on other sites More sharing options...
Danp2 Posted December 27, 2019 Share Posted December 27, 2019 See the remarks section for RunWait in the help file, specifically -- Quote To run DOS commands, try RunWait(@ComSpec & " /c " & "commandName") ; don't forget " " before "/c" Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
TanjimReza Posted December 27, 2019 Author Share Posted December 27, 2019 42 minutes ago, Danp2 said: See the remarks section for RunWait in the help file, specifically -- I've been trying to figure out for a long time. Note: I'm not running any commands directly, I'm running a batch file . Even tried ProcesssWaitClose("cmd.exe") Link to comment Share on other sites More sharing options...
Musashi Posted December 27, 2019 Share Posted December 27, 2019 (edited) 3 hours ago, TanjimReza said: I've been trying to figure out for a long time. Here is a small test environment : * create a test directory (this works as your @ScriptDir) * copy Run-bat.au3 there * copy Test-Batman.zip there and unzip it (Batman.zip inside is just a dummy for testing) Run-bat.au3 : #include <AutoItConstants.au3> #include <WinAPIShPath.au3> Local $sFilePath = @ScriptDir & "\Folder1" Local $sDeleteFile = @ScriptDir & "\Batman.zip" Local $iPID = Run($sFilePath & "\script.cmd","", @SW_SHOW) ; later @SW_HIDE If Not @error Then If ProcessWaitClose($iPID) Then ConsoleWrite("+ >>>>>> @@DEBUG > OK : ProcessWaitClose " & @CRLF) If FileDelete($sDeleteFile) Then ConsoleWrite("+ >>>>>> @@DEBUG > OK : FileDelete " & @CRLF) Else ConsoleWrite("! >>>>>> @@DEBUG > ERROR : FileDelete " & @CRLF) EndIf If DirRemove(_WinAPI_PathAddBackslash($sFilePath), $DIR_REMOVE) Then ConsoleWrite("+ >>>>>> @@DEBUG > OK : DirRemove " & @CRLF) Else ConsoleWrite("! >>>>>> @@DEBUG > ERROR : DirRemove " & @CRLF) EndIf Else ConsoleWrite("! >>>>>> @@DEBUG > ERROR : ProcessWaitClose " & @CRLF) EndIf ConsoleWrite(@CRLF) Else ConsoleWrite("! >>>>>> @@DEBUG > ERROR : RUN " & @CRLF & @CRLF) EndIf Test-Batman.zip Edited December 27, 2019 by Musashi typo "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
TanjimReza Posted December 28, 2019 Author Share Posted December 28, 2019 9 hours ago, Musashi said: Here is a small test environment : * create a test directory (this works as your @ScriptDir) * copy Run-bat.au3 there * copy Test-Batman.zip there and unzip it (Batman.zip inside is just a dummy for testing) Run-bat.au3 : #include <AutoItConstants.au3> #include <WinAPIShPath.au3> Local $sFilePath = @ScriptDir & "\Folder1" Local $sDeleteFile = @ScriptDir & "\Batman.zip" Local $iPID = Run($sFilePath & "\script.cmd","", @SW_SHOW) ; later @SW_HIDE If Not @error Then If ProcessWaitClose($iPID) Then ConsoleWrite("+ >>>>>> @@DEBUG > OK : ProcessWaitClose " & @CRLF) If FileDelete($sDeleteFile) Then ConsoleWrite("+ >>>>>> @@DEBUG > OK : FileDelete " & @CRLF) Else ConsoleWrite("! >>>>>> @@DEBUG > ERROR : FileDelete " & @CRLF) EndIf If DirRemove(_WinAPI_PathAddBackslash($sFilePath), $DIR_REMOVE) Then ConsoleWrite("+ >>>>>> @@DEBUG > OK : DirRemove " & @CRLF) Else ConsoleWrite("! >>>>>> @@DEBUG > ERROR : DirRemove " & @CRLF) EndIf Else ConsoleWrite("! >>>>>> @@DEBUG > ERROR : ProcessWaitClose " & @CRLF) EndIf ConsoleWrite(@CRLF) Else ConsoleWrite("! >>>>>> @@DEBUG > ERROR : RUN " & @CRLF & @CRLF) EndIf Test-Batman.zip 523 B · 0 downloads I'll try it !! Thanks! Link to comment Share on other sites More sharing options...
TanjimReza Posted December 28, 2019 Author Share Posted December 28, 2019 2 hours ago, TanjimReza said: I'll try it !! Thanks! This works! Thanks to you. I got to learn something new!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now