Jump to content
Sign in to follow this  
speedi

does the script wait until a command is finished?

Recommended Posts

speedi

I have a script that contains these 3 commands

DirRemove("C:\Testdir", 1)

DirCreate("C:\Testdir")

exit

I do this after copying many files and folders into the \testdir folder (It is a computer speed test) - sometimes the c:\testdir does not get created before the exit.

Does the script wait until the dirremove is finished before executing the next command? Thanks!

Share this post


Link to post
Share on other sites
Jos

I have a script that contains these 3 commands

DirRemove("C:\Testdir", 1)

DirCreate("C:\Testdir")

exit

I do this after copying many files and folders into the \testdir folder (It is a computer speed test) - sometimes the c:\testdir does not get created before the exit.

Does the script wait until the dirremove is finished before executing the next command? Thanks!

The commands are performed sequencial.

Could be the OS isn't done yet, but have you checked the RC and @error returned by the DirCreate() function?


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
speedi

The commands are performed sequencial.

Could be the OS isn't done yet, but have you checked the RC and @error returned by the DirCreate() function?

What is RC??

Share this post


Link to post
Share on other sites
speedi

Stands for RuturnCode or Return Value.

$RC = DirCreate()
I tired several ideas I had - did not work

I tired this:

DirCreate("C:\Testdir")

while @error = 1

DirCreate("C:\Testdir")

WEnd

that didn't work... Can you tell me how to code this part???? Thanks a ton! Jim

Share this post


Link to post
Share on other sites
martin

I tired several ideas I had - did not work

I tired this:

DirCreate("C:\Testdir")

while @error = 1

DirCreate("C:\Testdir")

WEnd

that didn't work... Can you tell me how to code this part???? Thanks a ton! Jim

There is no use made of @error in the DirCreate function as far as I can see. If the problem is that DirRemove returns before the folder is actually removed then you could check for its existence. Also, check the return from DirRemove, although from what you say that doesn't appear to be a problem.

Local $maxtry = 5, $tries = 0

If DirRemove("C:\Testdir", 1) Then
    While FileExists("C:\Testdir\..")
        Sleep(100);might need to add something here to stop getting stuck
    WEnd
    
    While DirCreate("C:\Testdir") = 0
        $tries += 1
        If $tries = $maxtries Then ExitLoop
        sleep(200)
    WEnd

    If $tries = $maxtries Then MsgBox(0, "ERROR", "Could not create 'C:\Testdir'")
Else
    MsgBox(0, "ERROR", "Cannot remove 'C:\testdir'")
EndIf

I don't think that would dare to fail. :)

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
speedi

There is no use made of @error in the DirCreate function as far as I can see. If the problem is that DirRemove returns before the folder is actually removed then you could check for its existence. Also, check the return from DirRemove, although from what you say that doesn't appear to be a problem.

Local $maxtry = 5, $tries = 0

If DirRemove("C:\Testdir", 1) Then
    While FileExists("C:\Testdir\..")
        Sleep(100);might need to add something here to stop getting stuck
    WEnd
    
    While DirCreate("C:\Testdir") = 0
        $tries += 1
        If $tries = $maxtries Then ExitLoop
        sleep(200)
    WEnd

    If $tries = $maxtries Then MsgBox(0, "ERROR", "Could not create 'C:\Testdir'")
Else
    MsgBox(0, "ERROR", "Cannot remove 'C:\testdir'")
EndIf

I don't think that would dare to fail. :)

I tried your code and had the same result. the folder isn't created for some reason... I am trying DOS commands now with runwait. If you have any other ideas, please let me know... thanks for your help...

Share this post


Link to post
Share on other sites
martin

I tried your code and had the same result. the folder isn't created for some reason... I am trying DOS commands now with runwait. If you have any other ideas, please let me know... thanks for your help...

Sorry, typing/brain error; "C:\Testdir\.." should have been "C:\Testdir\."

I find it difficult to believe you need to resort to DOS commands for this.

Can you tell me what the output or result is for this

Local $maxtry = 5, $tries = 0
If FileExists("C:\Testdir\.") Then
    If DirRemove("C:\Testdir", 1) = 0 Then
        MsgBox(0, "ERROR", "Cannot remove 'C:\testdir'")
        Exit
    Else
        MsgBox(0, "Success", "C:\Testdir removed")
    EndIf

EndIf


While FileExists("C:\Testdir\.")
    $tries += 1
    If $tries = $maxtry Then
        MsgBox(0, "ERROR", "C:\Testdir is not being removed")
        Exit
    EndIf
    
    Sleep(500);might need to add something here to stop getting stuck
WEnd

$tries = 0
While DirCreate("C:\Testdir") = 0
    $tries += 1
    If $tries = $maxtry Then
        MsgBox(0, "ERROR", "Cannot create C:|Testdir")
        Exit
    EndIf
    
    Sleep(200)
WEnd

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
speedi

It is quite simple.

I plan to upgrade my notebook with more memory and a larger hard disk so I want to run a speed test before and after.

My script is the speed test and the troublesome part is where I copy most but not all files and folders from "My Documents" to a folder called "testdir". My script records the start and end time and displays the elapsed time when finished.

Finally, I want to clear the "testdir" folder to cleanup.... I want to use the "dirremove" so I need not worry about system files or read only files interupting a delete all type function.... the number of files is significant....

Then lastly I want the "testdir" established again before I exit the script...

That isn't to complicated I believe....

Thanks for taking the time..... Jim

Edited by speedi

Share this post


Link to post
Share on other sites
martin

It is quite simple.

I plan to upgrade my notebook with more memory and a larger hard disk so I want to run a speed test before and after.

My script is the speed test and the troublesome part is where I copy most but not all files and folders from "My Documents" to a folder called "testdir". My script records the start and end time and displays the elapsed time when finished.

Finally, I want to clear the "testdir" folder to cleanup.... I want to use the "dirremove" so I need not worry about system files or read only files interupting a delete all type function.... the number of files is significant....

Then lastly I want the "testdir" established again before I exit the script...

That isn't to complicated I believe....

Thanks for taking the time..... Jim

But do you have an answer to my post?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
speedi

But do you have an answer to my post?

If you mean have I tried the change, I am doing it now...

Share this post


Link to post
Share on other sites
FreeFry

Would not reading and writing a file to the drive be a more 'reliable' test, than creating a folder?

Share this post


Link to post
Share on other sites
AdmiralAlkex

Would not reading and writing a file to the drive be a more 'reliable' test, than creating a folder?

Would not reading and writing thousands of files be enough?? (läs post 10 igen!!)

Share this post


Link to post
Share on other sites
FreeFry

Ow, that's what happens when one scimms through posts. >_> Only read the "record start and end time" part lol. :)

Share this post


Link to post
Share on other sites
speedi

I copied your code and pasted it....

the messages I had are

"testdir removed"

then

"testdir not being removed"

testdir was removed, but as before not created....

Share this post


Link to post
Share on other sites
speedi

FINAL SOLUTION

This is the code that is now working:

*****************************************

WinClose("PowerDesk -> C:\testdir\*.*","") ; close it so it is not an issue

WinWaitClose("PowerDesk -> C:\testdir\*.*","")

sleep(30000)

DirRemove("C:\testdir",1)

While FileExists("C:\testdir")

WEnd

MsgBox(4096,"" , "C:\testdir is now gone")

DirCreate("C:\testdir")

MsgBox(4096,"" , "C:\testdir is back!!!")

exit

******************************************

NOTE! Powerdesk is a file management program and since it was showing c:\testdir at the point the dirremove was done, I thought it might be part of the problem, so I used the 1st 2 lines of code above to close that window....

Thanks for everyones help!!!

Share this post


Link to post
Share on other sites
martin

FINAL SOLUTION

This is the code that is now working:

*****************************************

WinClose("PowerDesk -> C:\testdir\*.*","") ; close it so it is not an issue

WinWaitClose("PowerDesk -> C:\testdir\*.*","")

sleep(30000)

DirRemove("C:\testdir",1)

While FileExists("C:\testdir")

WEnd

MsgBox(4096,"" , "C:\testdir is now gone")

DirCreate("C:\testdir")

MsgBox(4096,"" , "C:\testdir is back!!!")

exit

******************************************

NOTE! Powerdesk is a file management program and since it was showing c:\testdir at the point the dirremove was done, I thought it might be part of the problem, so I used the 1st 2 lines of code above to close that window....

Thanks for everyones help!!!

Well I'm glad you solved it. Might have been a good idea to mention Powerdesk before.

It reminds me (unfairly) of a case some years ago when a customer phoned me up and told me to get someone there as fast as possible because the machine he had bought from me had stopped working. I sent an engineer. When the engineer arrived 3 hours later he reported back that the customer had dropped 2 tons of glass onto the machine from a height of about 4 feet above the machine and seriously damaged it. Obviously the customer didn't think that was worth mentioning. (We got his machine back in action in 2 days.)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
speedi

Well I'm glad you solved it. Might have been a good idea to mention Powerdesk before.

It reminds me (unfairly) of a case some years ago when a customer phoned me up and told me to get someone there as fast as possible because the machine he had bought from me had stopped working. I sent an engineer. When the engineer arrived 3 hours later he reported back that the customer had dropped 2 tons of glass onto the machine from a height of about 4 feet above the machine and seriously damaged it. Obviously the customer didn't think that was worth mentioning. (We got his machine back in action in 2 days.)

Well now I am not so sure that Powerdesk was the problem. I ran the routine 10 times without a glitch 8 of the ten....

Twice it stopped while doing the dirremove (powerdesk was closed at that time).. Both times when I looked at \testdir with windows explorer, all the files were gone except one (each time the file left was different). The script is still active at this point and when I try to delete the file via windows explorer, it will not allow it saying is is being used by another process (autoit script I think).... all applications are closed before I run this script and I even turn off the wifi internet access. I have one more idea. I didn't think about the "threatfire" security software that is running all the time... I will disable threatfire and try again several times.... I will post my experience.... thanks! actually I am getting tired of fooling with this especially since my objective speed test is accomplished - this part is just cleaning up....

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×