Jump to content

Change time for the file


cparadis
 Share

Recommended Posts

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

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