Forum Discussion

SangeetNenwani's avatar
SangeetNenwani
Contributor
3 years ago
Solved

open file in hex format

I want to read and edit a file.
If one open that file normally it has stranger characters. But if with use of Notepad++ and hex view, its readable.
Now I want to read the file in testcomplete and edit in it.
is there any possible way for it?

  • I have found another solution. Writing here if someone needs this thing in future.

     

    //open as binary file

    var binFile = aqFile["OpenBinaryFile"](stringFilePathBinFile, aqFile["faReadWrite"]);

    // Reads bytes from the file
    readBytesFromBin = binFile["ReadBytes"]();

    // Obtains the number of items in the array returned by ReadBytes()
    countBytes = readBytesFromBin["Count"];
    for (var i = 0; i < countBytes; i++)
    {
    // Obtains the current item
    var byteValue = readBytesFromBin["Item"](i);

    //convert it to ascii code and store it in string
     var stringBinFile =stringBinFile+ aqConvert["VarToStr"](aqString["Format"]("%c", aqConvert["VarToInt"](byteValue)));
    }

6 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    You can try launching notepad++ from a command line and see if that helps.

     

    If you are using this file for data in your test, I would suggest saving different versions of the file with the different data sets and calling those as you need them rather than trying to do this intricate sort of editing as you go.  

    • SangeetNenwani's avatar
      SangeetNenwani
      Contributor

      Hello Marsha_R 

      Thanks for the response.

      Reasons because of which I don’t want to use other software like notepad++ or save in specific format:

      1) There are multiple people using multiple PC’s for testing same application, that’s means if someone want to use that file function, he/she must have notepad++ with Hex plugin.

      2) Original file can change in with every project I am opening in my testing software (it’s a temp file). Means I must convert it manually after every time I open a new project.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    TestComplete does not provide hex file editor.

    Can you post/attach here a sample file?

     

    • SangeetNenwani's avatar
      SangeetNenwani
      Contributor

      Hello AlexKaras 
      It's a .dll file. Its not supported here.
      Anyways, I used the function to open the file as Binary and editing file as byte data. Which is working for now. But I am not sure if it is good method or not.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        I am not sure if it is good method or not.

        I think this is acceptable method because, as you correctly noted, binary file edit is not something that TestComplete is oriented at and thus it does not provide hex editor.

        From programming point of view your method is quite correct, as for me.