Skip to content
Advertisement

fopen() returns inavlid argument when writing on SD card?

I’m trying to write a file on SD card if it’s inserted into the kit. Otherwise, the file should be written to the current directory of the project.

I can write the file in the project’s directory without any problems. However, when I try to write it on the inserted SD card, it returns Invalide argument!

JavaScript

I tried changing the :s into -s in the file name. This caused the error to change to Input/output error.

I also tried not to use chdir(). Instead, to directly do the following:

JavaScript

This didn’t solve the problem -> Invalid argument.

I’m sure that the SD card is mounted to /media/sdcard/ and I can create a file into it using the terminal without any problem.

What can cause this error and how to solve it?

UPDATE

I made sure that the SD card is correctly mounted before running the program. This didn’t solve the problem.

Besides, when I try to write the file into SD card with a normal name, and not the current data and time, it works without any problems!!

Following is my updated code:

JavaScript

Advertisement

Answer

The SD card is probably using a FAT/NTFS file system and filenames in a FAT/NTFS file system cannot contain the : character (and a few others).

If you replace the : in the format string by -, then it should work also on the SD card.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement