# [SOLVED]how to determine the size of a file? VHDL

Status
Not open for further replies.

#### linuxunil

##### Newbie level 3
I need to check if two files are identical.

I need to avoid this:
# ** Fatal: (vsim-3336) Attempt to read past the end of file

this error happens when it reads files that are different because they have different sizes.

At the moment, I want to insert a block that checks the file size, because if it is different i no longer need to see the rest.

But what i do?

#### TrickyDicky

there is no way to do this easily in VHDL. VHDL is not set up to do File io nicely other than text.

What file are you trying to read? For every file you can use the ENDFILE() function to see if you have reached the end of a file:

eg.
Code:
while not ENDFILE(my_file) loop
...etc
end loop;

You could use this loop method to count the number of lines in a text file, or if you are using modelsim you can do this with bytes in a binary file, but its not very neat.

Otherwise, I suggest you make sure all your files are the same length before you try and read them.

#### linuxunil

##### Newbie level 3
there is no way to do this easily in VHDL. VHDL is not set up to do File io nicely other than text.

What file are you trying to read? For every file you can use the ENDFILE() function to see if you have reached the end of a file:

eg.
Code:
while not ENDFILE(my_file) loop
...etc
end loop;

You could use this loop method to count the number of lines in a text file, or if you are using modelsim you can do this with bytes in a binary file, but its not very neat.

Otherwise, I suggest you make sure all your files are the same length before you try and read them.

I want to compare any two files to see if they are exactly alike. I already knew "ENDFILE." The problem happens when the files were different and therefore have different sizes.

I found a simple solution:

while not (ENDFILE (file1)) loop

if not (ENDFILE (file2)) then
end if;
end loop;

so it will read the entire file1, but if he reaches the end of file2 before, buffer2 will contain only the last part of file2. and so I can know if there are differences between the files through a variable that I use.

Status
Not open for further replies.