【发布时间】:2023-04-11 05:50:01
【问题描述】:
我在 Raspberry Pi 4 上运行 Ubuntu 19.10。我需要记录一些数据,因此将 USB 记忆棒插入 PI 并希望将记录保存到此位置。
我通过mount检查了路径:
/dev/sda1 on /media/ubuntu/USB DISK
所以我将我的应用程序的dataPath 设置为:media/ubuntu/USB DISK/records。
在我的应用程序中,我有以下功能:
time_t ct = time(0);
mkdir(dataPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); //this works: creates /records on the disk
//chmod(dataPath.c_str(), 0777)
tm *ltm = localtime(&ct);
String timeStr = format("%i_%i_%i_%i:%i:%i", 1900+ltm->tm_year, 1+ltm->tm_mon
, ltm->tm_mday, 1+ltm->tm_hour, 1+ltm->tm_min, 1+ltm->tm_sec);
String fullPath = dataPath + "/" + timeStr;
const char *c = fullPath.c_str(); // /media/ubuntu/USB DISK/records/2020_6_15_8:30:3
auto f = mkdir(c, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
第一个mkdir 命令在USB 磁盘上运行并创建/media/ubuntu/USB DISK/records/。
但是应该创建/media/ubuntu/USB DISK/records/2020_6_15_8:30:3 的第二个命令不起作用。 records 目录下没有子文件夹。
我的脚本开头是:sudo ./main
任何想法,可能是什么问题?
【问题讨论】:
-
colon ":" is special symbol in M$ (FAT / exFAT / NTFS) file systems - 试试“%i_%i_%i_%i_%i_%i”。
标签: ubuntu raspberry-pi mkdir