Sign in to follow this  
Followers 0
Meerecat

Modifying Save as Function

6 posts in this topic

Hello

I am playing around with the File Encryption example in the AutoIT help.

I would like to change it so that whatever the input file is called, the output file is the same with a different extension.

So test.txt input becomes text.myext output.

I think this is the bit of code I need to change:

Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $InFileButton
            $file = FileOpenDialog("Input File", "", "All files (*.*;)")
            If $file <> "" Then GUICtrlSetData($InFileInput, $file)
        Case $OutFileButton
            $file = FileSaveDialog("Output file", "", "Any file (*.*;)")
            If $file <> "" Then GUICtrlSetData($OutFileInput, $file)

        Case $EncryptButton
            $infile = GUICtrlRead($InFileInput)
            If Not FileExists($infile) Then
                MsgBox(16, "Error", "Input file doesn't exists!")
                ContinueLoop
            EndIf

However if I have misread the code and it is somewhere else, then the script I am working from is the example script in the help for _Crypt_EncryptFile

Many thanks for your help.


Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Share this post


Link to post
Share on other sites



Just one line may help you in this Case. Just some string handling and the GUICtrlSetData() to the $OutFileInput handle.

Case $InFileButton
            $file = FileOpenDialog("Input File", "", "All files (*.*;)")
            If $file <> "" Then
                GUICtrlSetData($InFileInput, $file)
                ; get position of "." and keep chars on left of "." and then concant with myext
                GUICtrlSetData($OutFileInput, StringLeft($file, StringInStr($file, '.', 0, -1)) & 'myext')
            EndIf

Share this post


Link to post
Share on other sites

Just one line may help you in this Case. Just some string handling and the GUICtrlSetData() to the $OutFileInput handle.

Case $InFileButton
            $file = FileOpenDialog("Input File", "", "All files (*.*;)")
            If $file <> "" Then
                GUICtrlSetData($InFileInput, $file)
                ; get position of "." and keep chars on left of "." and then concant with myext
                GUICtrlSetData($OutFileInput, StringLeft($file, StringInStr($file, '.', 0, -1)) & 'myext')
            EndIf

Thank you very much. Seems to work perfectly :huh2:

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Share this post


Link to post
Share on other sites

Hello again

I am still struggling with this. My problem is when it comes to decrypting the file, renaming the extension back to whatever the extension should be eg .txt, .doc, .docx etc.

I figured the easiest way to do this was to add the .crypt AFTER the original 3 or 4 digit extension, but I am struggling to achieve this.

Can anybody suggest how I would achieve this? Also how easy would it be to remove the .crypt extension when it comes to decryption?

Many thanks for any suggestions.

Lee


Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Share this post


Link to post
Share on other sites

Adding ".crypt" to the original extension seems like a good idea. You could also set the out file automatically with the ".crypt" extension and use FileSelectFolder() to set the destination path.

Here is an example of adding and removing the ".crypt" extension

$InFile = 'test.txt'
$Extension = '.crypt'

; get length of ".crypt" extension
$TrimLength = StringLen($Extension)

; add .crypt extension
$CryptFile = $InFile & $Extension

; remove .crypt extension
$OutFile = StringTrimRight($CryptFile, $TrimLength)

MsgBox(0, @ScriptName, _
        '$InFile = ' & $InFile & @CRLF & _
        '$Extension = ' & $Extension & @CRLF & _
        '$CryptFile = ' & $CryptFile & @CRLF & _
        '$TrimLength = ' & $TrimLength & @CRLF & _
        '$OutFile = ' & $OutFile)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Adding ".crypt" to the original extension seems like a good idea. You could also set the out file automatically with the ".crypt" extension and use FileSelectFolder() to set the destination path.

Here is an example of adding and removing the ".crypt" extension

$InFile = 'test.txt'
$Extension = '.crypt'

; get length of ".crypt" extension
$TrimLength = StringLen($Extension)

; add .crypt extension
$CryptFile = $InFile & $Extension

; remove .crypt extension
$OutFile = StringTrimRight($CryptFile, $TrimLength)

MsgBox(0, @ScriptName, _
        '$InFile = ' & $InFile & @CRLF & _
        '$Extension = ' & $Extension & @CRLF & _
        '$CryptFile = ' & $CryptFile & @CRLF & _
        '$TrimLength = ' & $TrimLength & @CRLF & _
        '$OutFile = ' & $OutFile)

Thank you for your reply. I am having difficulties adding this to my existing script:

Case $InFileButton
            $file = FileOpenDialog("Input File", "", "All files (*.*;)")
            If $file <> "" Then
                GUICtrlSetData($InFileInput, $file)
                $CryptFile = $InFile & $Extension

                

            EndIf
        Case $OutFileButton
            $file = FileSaveDialog("Output file", "", "Any file (*.*;)")
            $CryptFile = $InFile & $Extension

Sorry if I've made very stupid misunderstandings, this is only my 2nd AutoIT script.

Ignore that, I've reread your comments in both scripts and spent some time in the Help file.

This seems to work:

Case $InFileButton
            $file = FileOpenDialog("Input File", "", "All files (*.*;)")
            If $file <> "" Then
                GUICtrlSetData($InFileInput, $file)
                GUICtrlSetData($OutFileInput, $file & $Extension)
            EndIf

Many thanks for your help, no doubt I'll be back :huh2:

Edited by Meerecat

Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

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