Jump to content

Filename + 1


Recommended Posts

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!!

Link to comment
Share on other sites

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 ...
 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Not certain about the answer to that, but the syntax you had is valid, just not fit for purpose.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
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
 Share

  • Recently Browsing   0 members

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