Jump to content

Open and SaveAs file with another format


Recommended Posts

5 minutes ago, Sivasankar said:

I am new to AutoIt . I have number of files in a folder, need to open the file one by one. Once it opened, saveas file with some other format. is it possible to achieve using AutoIt.

Please advise 

You need _FileListToArrayRec then For Next loop, and open the files with ShellExecute()

Link to comment
Share on other sites

It depends.
Which types of files (Word, Excel ...) do you need to open and save in another format (PDF ...)?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@rootx : Thanks for your reply, I got the list of files from folder using FileListToArrayRec. then opened the each document using For Next loop, now I need to do SaveAs the file with same name  but different format. I am facing problem like couldn't able to open SaveAs dialog window. 

Here I tried to convert file docx to rtf. but my actual requirement is convert file .SEG to TIFF format

@232showtime: Please check below code, correct me if iam wrong,

 

#include <Array.au3> 
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>
#include <FileConstants.au3>
#include <StringConstants.au3>

Example()

Func Example()
    Local $sAutoItDir = StringLeft(@ScriptDir, StringInStr(@ScriptDir, "\", Default, -1))
    If StringRight($sAutoItDir, 5) = "beta\" Then
        $sAutoItDir = StringTrimRight($sAutoItDir, 5)
    EndIf
    ConsoleWrite($sAutoItDir & @CRLF)

$aArray = _FileListToArrayRec($sAutoItDir, "*.docx", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
    _ArrayDisplay($aArray, ".Docx Files")

For $i =1 to $aArray[0]
   MsgBox($MB_SYSTEMMODAL, "", "Count down!" & @CRLF & $aArray[$i])
   
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
       "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
       
Local $sDocument = $aArray[$i]
Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
        "Error opening 'open _Word_Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
     
local $szDrive, $szDir, $szFName, $szExt
_PathSplit($aArray[$i], $szDrive, $szDir, $szFName, $szExt)
MsgBox(0, $aArray[$i], $szDrive & $szDir);

Local $sMessage = "Choose a filename."
;Local $sFileSaveDialog = FileSaveDialog($sMessage, "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Scripts (*.xlsx)", $FD_PATHMUSTEXIST,$szFName)
Local $sFileSaveDialog = FileSaveDialog($sMessage, $szDrive & $szDir & "te" , "Scripts (*.rtf)", $FD_PATHMUSTEXIST,$szFName)

   If @error Then
      MsgBox($MB_SYSTEMMODAL, "", "No file was saved.")
   Else
      Local $sFileName = StringTrimLeft($sFileSaveDialog, StringInStr($sFileSaveDialog, "\", $STR_NOCASESENSE, -1))
      Local $iExtension = StringInStr($sFileName, ".", $STR_NOCASESENSE)

      If $iExtension Then       
         If Not (StringTrimLeft($sFileName, $iExtension - 1) = ".rtf") Then $sFileSaveDialog &= ".rtf"
      Else
         $sFileSaveDialog &= ".rtf"
      EndIf
      
      MsgBox($MB_SYSTEMMODAL, "", "You saved the following file:" & @CRLF & $sFileSaveDialog)
   EndIf

Next
EndFunc   ;==>Example

 

Link to comment
Share on other sites

22 hours ago, Sivasankar said:

Once it opened, saveas file with some other format. is it possible to achieve using AutoIt.

Have you tried having it this way? Other formats were added in "FileSaveDialog()":

Local $sFileSaveDialog = FileSaveDialog($sMessage, $szDrive & $szDir & "te" , "TIFF (*.tiff)|JPEG (*.jpeg)|PNG (*.png)", $FD_PATHMUSTEXIST,$szFName)

 

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

You can't use FileSaveDialog in this way. To save a document from Word you need to use _Word_DocSaveAs or _Word_DocExport.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

BTW: You shouldn't have _Word_Create inside the

For $i =1 to $aArray[0]

loop. Open Word one time at the top of your script and close it before the script ends.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Please ignore above code. My requirement is, convert Mainframe file into image format using ELIXIR tool, but manually it takes too long. So plan to achieve the scenario with AutoIT. 

1. Get all files from a folder

2. Open each .SEG format file in "ELIXIR" tool

3. Then SaveAs the file with .TIFF format in another location. 

Please advise

Link to comment
Share on other sites

I'm not familiar with the tool, and all the docs I've seen for what I "think" it might be...it looks like a fairly old application.  I would look through the documentation to see if there are any command-line operations to execute the tool and do the conversion.  That may be the easiest and/or most elegant way to automate it.    Otherwise, you can try automating keystrokes and clicks based on keyboard shortcuts and window location.  What would be ideal is if you can use the Au3Info tool included with AutoIt to identify the controls in the GUI and use the more robust Control* functions to automate the GUI...much less room for error versus sending keystrokes and mouse clicks.

Link to comment
Share on other sites

  • 2 weeks later...
On 17/5/2017 at 7:41 AM, Sivasankar said:

Please ignore above code. My requirement is, convert Mainframe file into image format using ELIXIR tool, but manually it takes too long. So plan to achieve the scenario with AutoIT. 

1. Get all files from a folder

2. Open each .SEG format file in "ELIXIR" tool

3. Then SaveAs the file with .TIFF format in another location. 

Please advise

1. use _FileListToArrayRec to get all file.... .SEG

2. Inside the loop FOR ... NEXT execute ELIXIR tool to convert it one by one

3 Put an If control to chek if the file is converted and exist than copy it with filecopy

PS: you need to set ELIXIR global varible in windows and test it with cmd if everithing is ok you can use shellexecutewait or Runwait

Edited by rootx
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...