Sign in to follow this  
Followers 0
cparadis

Change time for the file

4 posts in this topic

Here is my code.

I don't know whats wrong. So i have write some comments, a lot more easy to read.

I want to change the date for a file, with this code. But it seems like it doesn't work.

;Make the file
iniwrite("testing.ini", "test", "test", "test")

Dim $test, $data, $date, $x

;Set the directory and file path.
$test = @ScriptDir & "\testing.ini"

;Help text.
$text = "Change time for a file" & @cr & @cr & "YYYY MM DD HH:MM:SS" & @cr & @cr & "Example:" & @cr & @cr & "2008 06 02 13:02:23"

;The inputbox.
$data = inputbox("Change time", $text , "2008 06 02 13:02:23", "", "100", "200")


;If error is clean
if @error = 0 Then
    
    ;If the line is 19 character.
    if StringLen($data) = 19 Then
        
        ;Remove space and :
        $date = StringReplace($data, chr(32), "")
        $date = StringReplace($data, chr(58), "")
        
        ;Set the date for the file. Modified, Created and Accessed.
        
        for $x = 0 to 2
            
            FileSetTime($test, $date, $x)
            
            ;If something is wrong with settime.
            if @error = 0 Then
                MsgBox(0, "", "error")
            EndIf
            
        Next
        
        ;If something is wrong with the data.
        Else
        
        msgbox(0, "", "Error")
        
    Endif
    
EndIf

Share this post


Link to post
Share on other sites



study these two lines...

$date = StringReplace($data, chr(32), "")

$date = StringReplace($data, chr(58), "")

therein is your mistake...

$date ... $data

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

To debug this you can always MsgBox() your variable before the failing Function to see if your passed data is valid.

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

To debug this you can always MsgBox() your variable before the failing Function to see if your passed data is valid.

Lar.

Thanks. Now i see where the problem is.

$date = StringReplace($data, chr(32), "")

$date = StringReplace($data, chr(58), "")

And that will be $date. Thanks for the quick help. :mellow:

Seems like the settime will not work correctly. Got error for it.

I can't see more mistakes in the code.

;Make the file
iniwrite("testing.ini", "test", "test", "test")

Dim $test, $data, $date

;Set the directory and file path.
$test = @ScriptDir & "\testing.ini"

;Help text.
$text = "Change time for a file" & @cr & @cr & "YYYY MM DD HH:MM:SS" & @cr & @cr & "Example:" & @cr & @cr & "2008 06 02 13:02:23"

;The inputbox.
$data = inputbox("Change time", $text , "2008 06 02 13:02:23", "", "100", "200")


;If error is clean
if @error = 0 Then
    
    ;If the line is 19 character.
    if StringLen($data) = 19 Then
        
        ;Remove space and :
        $date = StringReplace($data, chr(32), "")
        $date = StringReplace($date, chr(58), "")
        ;Set the date for the file. Modified, Created and Accessed.
        
        for $x = 0 to 2
            
            FileSetTime($test, $date, $x)
            
            ;If something is wrong with settime.
                if @error = 0 Then
                    MsgBox(0, "", "error")
                EndIf
            
        Next
        
        ;If something is wrong with the data.
        Else
        
        msgbox(0, "", "Error")
        
    Endif
    
EndIf
Edited by cparadis

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  
Followers 0