Search code examples
autoit

Copying the contents of file to another


I am new to Auto It and I want to copy the contents of a file(any type) to another by creating a word document on the hard drive using Auto It script.

Could anyone help me please?

Note: I want to open a file, read the contents and write them to another file by creating it in any specified location as per my wish.

Please help me in this aspect

Thanks in adv


Solution

  • ;$sourceFile="c:\source.file"
    ;$destFile="c:\dest.file"
    
    ; Open source file, file must exist
    $sourceFile=FileOpenDialog("Source file", "c:\", "All(*.*)", 1)
    If @error Then
        MsgBox("No file choosen")
        Exit
    EndIf
    
    ; Open dest file
    $destFile=FileOpenDialog("Destination file", "c:\", "All(*.*)")
    If @error Then
        MsgBox("No file choosen")
        Exit
    EndIf
    
    $result=FileCopy($sourceFile, $destFile)
    If ($result = 0) Then
        MsgBox("copy failed")
    EndIf