Jump to content

Recommended Posts

Posted

Hi everyone,

im working on a script that creates a file named xxxxx0.csv, and if already exists then name it xxxxx1.csv and so on.

problem is the loop freezes every time.. :)

here is the code:

$num = 0
$name = @ComputerName & "_perfmon_" & $num
$path = '"C:\PerfLogs\' & $name & '.csv"'

Do
    sleep(50)
    $num += 1

    $name = @ComputerName & "_perfmon_" & $num ;redundant? i try without this two lines anyways
    $path = '"C:\PerfLogs\' & $name & '.csv"'

Until not FileExists($path)

rest of the code..

i also try with While

$num = 0
$name = @ComputerName & "_perfmon_" & $num
$path = '"C:\PerfLogs\' & $name & '.csv"'

while 1
    sleep(50)
    If not FileExists($path) Then
        ExitLoop
    Else        
        $num += 1
        $name = $computername & "_perfmon_" & $num ;same with and without
        $path = '"C:\PerfLogs\' & $name & '.csv"' ;same with and without
    EndIf
WEnd

also tried this..

$num = 0
$name = @ComputerName & "_perfmon_" & $num
$path = '"C:\PerfLogs\' & $name & '.csv"'
$var = FileExists($path)

While $var = 1
    $num += 1
    $name = @ComputerName & "_perfmon_" & $num
    $path = '"C:\PerfLogs\' & $name & '.csv"'
    $var = FileExists($path)
WEnd

When the file does not exist the program works fine but when it does the program freezes.

i try putting a MsgBox right after the while for debugging and it never comes up.. so the program is not looping, just freezing..

any ideas??

thanks!!

Posted

Mmm. Try not to include those ["] quotes with FileExists()

$path = '"C:\PerfLogs\' & $name & '.csv"'
$path = 'C:\PerfLogs\' & $name & '.csv'

Add them when needed. -> Run*()

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Posted

Maybe it is because your file path contains '"' and they are not allowed in filename.

lol that do the magic

wonder why scite dont warn about this.. nor it makes the function terminate and @error something.

thanks a lot!

Posted

Mmm. Try not to include those ["] quotes with FileExists()

$path = '"C:\PerfLogs\' & $name & '.csv"'
$path = 'C:\PerfLogs\' & $name & '.csv'

Add them when needed. -> Run*()

This line looks wierd to me

$path = '"C:\PerfLogs\' & $name & '.csv"'

Try $path = 'C:\PerfLogs\' & $name & '.csv'

you are both right also.

thanks for the answers!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...