Jump to content

Read struct from .bin file!!!??


Go to solution Solved by Melba23,

Recommended Posts

Posted (edited)

Is it possible to set data in a struct from a .bin file like in C? thx!

example in C++:

struct stAccount
{
    stSocket Socket;

    short Status;
    char PacketBuffer[2048];

    stDataBase DataBase;
};

stAccount Client[5000];

void Request::Login(stAccount *n_Client)
{
    p20D *Packet = (p20D*)&n_Client->PacketBuffer;

    FILE *hFile = NULL;
    char *TMP = new char[100];

    sprintf(TMP, "DataBase\\Accounts\\%c\\%s.bin", GetFirstKey(Packet->Username), Packet->Username);

    SecureZeroMemory(&n_Client->DataBase, sizeof(stDataBase));

    fopen_s(&hFile, TMP, "rb"); // read binary
    fread(&n_Client->DataBase, sizeof(stDataBase), 1, hFile); // "strcpy to struct"
    fclose(hFile);
}
Edited by xbennY0
Posted (edited)

For example... 

I have 100 folders and each of these folders have another 50 folders within, within those 5000 folders (100 folders * 50 in each one) there are 20 .txt files containing some text.

Something like this:

 

...folder 1:

   - sub folder[1-1]:

          - data[1].txt

          - [...]

          - data[20].txt

   - [...]

          - [...]

   - sub folder[1-50]:

          - data[1].txt

          - [...]

          - data[20].txt

------------------------------------------------------------------------

...folder 2:

   - sub folder[2-1]:

          - data[1].txt

          - [...]

          - data[20].txt

   - [...]

          - [...]

   - sub folder[2-50]:

          - data[1].txt

          - [...]

          - data[20].txt

------------------------------------------------------------------------

...folder 3:

   - sub folder[3-1]:

          - data[1].txt

          - [...]

          - data[20].txt

   - [...]

          - [...]

   - sub folder[3-50]:

          - data[1].txt

          - [...]

          - data[20].txt

------------------------------------------------------------------------

...[...]:

------------------------------------------------------------------------

...folder 100:

   - sub folder[100-1]:

          - data[1].txt

          - [...]

          - data[20].txt

   - [...]

          - [...]

   - sub folder[100-50]:

          - data[1].txt

          - [...]

          - data[20].txt

 

I need to get all this information (including the name of the folders) and put into a struct! is it possible?

thanks!

Edited by xbennY0
Posted
Of couse yes.
 
_FileListToArrayRec to search the txt. and fileread+dllstructure.
 
Saludos
Posted (edited)
  On 11/2/2014 at 2:27 PM, Danyfirex said:

 

Of couse yes.
 
_FileListToArrayRec to search the txt. and fileread+dllstructure.
 
Saludos

 

Woww!! Thx bro!

then I want to save the struct in a binary file for easier reading(to not need to use the folders)

can you make a simple example??

best regards.

Edited by xbennY0
Posted

I think no need to use structure for that.

You simple should use _FileListToArrayRec+fileread+filewrite or filecopy

Saludos

Posted (edited)
  On 11/2/2014 at 4:11 PM, Danyfirex said:

I think no need to use structure for that.

You simple should use _FileListToArrayRec+fileread+filewrite or filecopy

Saludos

but I want something to remove these folders! I don't want to use them... like make a binary file with everything inside, you see?

Edited by xbennY0
Posted

SQL database?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 11/3/2014 at 3:24 AM, Rockerfeller said:

Do you mean like a zip file or something similar, with all the files in ?

Yes!

 

  On 11/3/2014 at 8:34 AM, guinness said:

SQL database?

How? this is a good idea?

Posted

There are examples of using archiving software to do what you want, do a search of the examples section for ZIP.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted
  On 11/4/2014 at 3:46 PM, BrewManNH said:

There are examples of using archiving software to do what you want, do a search of the examples section for ZIP.

but I do not want to work with the folders!! I want them as structs

Posted

Are you sure, do you even know what a struct is? What possible use would they be to you as a struct, and what would you do with the contents of this struct once yo've deleted the folders and put them inside it?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)
  On 11/4/2014 at 4:16 PM, BrewManNH said:

Are you sure, do you even know what a struct is? What possible use would they be to you as a struct, and what would you do with the contents of this struct once yo've deleted the folders and put them inside it?

of course i know... I would save it in a .bin to read it later, exactly the example that I gave in c++

the idea is to merge everything into one file(as a binary for example) excluding the folders.

Do this in c++ is easy i don't know here in autoit...

thanks for your help bro!

Edited by xbennY0
  • Moderators
Posted

xbennY0,

Why not just use _FileListToArrayRec to get all of these files into an array and then loop through it reading their content, adding this content to a single text file, and then deleting them? That sounds the quickest way of doing you want. :)

Although I would delete the files on a second pass - just in case something goes wrong. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

  On 11/4/2014 at 5:53 PM, Melba23 said:

xbennY0,

Why not just use _FileListToArrayRec to get all of these files into an array and then loop through it reading their content, adding this content to a single text file, and then deleting them? That sounds the quickest way of doing you want. :)

Although I would delete the files on a second pass - just in case something goes wrong. ;)

M23

Hm....but how i will be able to read this single file? is it possible put this contents(in the single file) in a struct to organize them?

Can you make a simple example?

thx again!

  • Moderators
Posted

xbennY0,

 

  Quote

is it possible put this contents(in the single file) in a struct to organize them?

You still have not really explained why you keep on about putting all this mass of data into a struct. What advantage does it give you over a single text file containing the content of all the files? Perhaps if you gave us a concrete example of what these files contain and what you mean by "organise" we might be a little wiser. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

  On 11/4/2014 at 7:27 PM, Melba23 said:

xbennY0,

 

You still have not really explained why you keep on about putting all this mass of data into a struct. What advantage does it give you over a single text file containing the content of all the files? Perhaps if you gave us a concrete example of what these files contain and what you mean by "organise" we might be a little wiser. :)

M23

Because it is easier to find one single file than 3.000. Because it transfers the program to a computer faster(with these folders takes about 15 minutes to transfer 3MB).

Edited by xbennY0
  • Moderators
Posted

xbennY0,

If all you requires is all the data in one file, then what I suggested in post #16 above should be what you need. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...