LONGJA
Posts: 23
Joined: Wed Mar 28, 2018 4:04 pm

Saving file to USB

Thu May 23, 2019 6:36 pm

Hi all,

I'm want to save a file to an external USB drive and would like to know the best way to do it.

At the moment the file is created and saved in the folder that I'm working in but I can't get it to land anywhere outside of that folder. The file is called settings.cfg so I have tried things along the lines of /home/pi/settings.cfg to put it elsewhere but no luck so far.

Any thoughts greatly appreciated.

Many thanks, James

Andyroo

Re: Saving file to USB

Thu May 23, 2019 6:45 pm

First thing you would have to do is mount the USB drive so the Pi operating system can find it.

You can use fstab or systemd to mount drives - a quick search on the forum will show lots of examples and fixes to problems.

Then you have to make sure the user running your program can read and write the mounted drive / folder.

Then you can hard code the folder location into your program (not great practice to be honest).

Have a look at fstab and mounting USB drives here to start :D

dl324
Posts: 122
Joined: Mon May 06, 2019 7:33 pm
Location: Pacific Northwest, USA

Re: Saving file to USB

Thu May 23, 2019 7:05 pm

LONGJA wrote:
Thu May 23, 2019 6:36 pm
I'm want to save a file to an external USB drive and would like to know the best way to do it.
Raspian Stretch with Desktop will mount the device for you. You should see it on the desktop and in /media/pi/<device>.

LONGJA
Posts: 23
Joined: Wed Mar 28, 2018 4:04 pm

Re: Saving file to USB

Thu May 23, 2019 7:06 pm

Thanks Andyroo, will start there

Andyroo

Re: Saving file to USB

Thu May 23, 2019 7:33 pm

dl324 wrote:
Thu May 23, 2019 7:05 pm
LONGJA wrote:
Thu May 23, 2019 6:36 pm
I'm want to save a file to an external USB drive and would like to know the best way to do it.
Raspian Stretch with Desktop will mount the device for you. You should see it on the desktop and in /media/pi/<device>.
But if you are not using the desktop or need a remote drive then you are stuck as automount does not work - it’s always best to control things manually then you understand things more. If you want everything automatic run Windows :lol: :lol: :lol: :lol: :lol: :lol:

Worse thing is if you create a program and assume things and then find out a Pi config has stopped auto-mount or renamed the drives as the power on sequence or USB port cabling changed :lol:

I did mean to mention that the free pdf (or buy the book to support the foundation) at https://www.raspberrypi.org/magpi/issue ... d-edition/ has a chapter on disks.

jahboater
Posts: 5413
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Saving file to USB

Thu May 23, 2019 7:52 pm

What has this to do with C/C++ ?

Perhaps the Rasbian section would be more appropriate?

dl324
Posts: 122
Joined: Mon May 06, 2019 7:33 pm
Location: Pacific Northwest, USA

Re: Saving file to USB

Thu May 23, 2019 8:13 pm

jahboater wrote:
Thu May 23, 2019 7:52 pm
What has this to do with C/C++ ?

Perhaps the Rasbian section would be more appropriate?
I thought about reporting that to moderators, but couldn't find an option to do it (in the prosilver board style).

Andyroo

Re: Saving file to USB

Thu May 23, 2019 8:18 pm

jahboater wrote:
Thu May 23, 2019 7:52 pm
What has this to do with C/C++ ?

Perhaps the Rasbian section would be more appropriate?
OP has a problem creating the file from a C or C++ program but seems to be unsure how to set the drives up to start with.

As for reporting it in ProSilver - Use the exclamation mark icon on each post.

Return to “C/C++”