- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
基本上我想做与系统调用 touch 相同的事情(如果文件不存在则创建文件,如果存在则更新其修改时间戳)。
std::string file = ...;
std::ofstream(file.c_str(), std::ios::app);
如果文件不存在,这将创建该文件。但不会改变修改时间。
std::string file = ...;
std::ofstream(file.c_str(), std::ios::out);
如果文件不存在,这将创建它,如果存在,它将更新修改时间,但如果文件存在,它也会截断文件。
那么我该如何触摸一个文件呢?
最佳答案
Kerrek SB 已发布解决方案,但不幸的是在 comment 中而不是答案(我宁愿接受他的回答)。
我在 utime(2) 上取得了成功:
#include <utime.h>
...
std::string path = "/path/to/my/file";
bool success = !utime(path.c_str(), 0);
关于C++ ofstream 不会改变 mtime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10677200/
我使用 mtime 和 find 。我是第一次交。 我看到一个将文件从一个位置移动到另一个位置的脚本。 `find . \ -mtime +0 -exec mv {} target \ ;` 我想了
所以我的问题是关于使用 find -mtime(以及 atime & ctime)。正如我所知,-mtime -n 搜索比 n 天新的文件,+n 比 n 天早的文件,-mtime n 搜索恰好 n 天
我正在尝试获取目录上的mtime。我不确定这是否是正确的方法,但是当目录中的文件发生更改时如何获取 mtime ? 这就是我目前正在做的事情: let statTs = fs.statSync(cfg
linux下的find命令在目录结构中搜索文件,并执行指定的操作。linux下的find命令提供了相当多的查找条件,功能很强大,由于find的功能很强大,所以他的选项也很多,今天我们来细说一下fin
我正在尝试在不使用 Matlab 内置函数(例如 fft())的情况下实现一维 DFT。这是我的代码 function [Xk] = dft1(xn) N=length(xn); n = 0:1:N-
做什么find -mtime -4和 find -mtime +4做?我无法理解手册页中给出的示例。 最佳答案 嗯,我可以。 -mtime n File's data was last modifie
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
基本上我想做与系统调用 touch 相同的事情(如果文件不存在则创建文件,如果存在则更新其修改时间戳)。 std::string file = ...; std::ofstream(file.c_st
我正在尝试使用 -mtime +(variable) 查找文件,但每次我在 GNU 中执行以下命令时都会收到错误消息: find: missing argument to `-mtime' 在 AIX
当我对/dev/input/event* 这样的输入设备文件进行统计时,我得到文件的 mtime 作为系统启动时间。 它至少应该获取击键并将文件的 mtime 更新为当前时间!! 有人知道这些输入设备
我在家里做了一个文件夹,我在里面摸了一个文件。现在我正在执行 find /home -mtime 1 但它没有找到任何东西。这正常吗? 最佳答案 你需要使用: find /home -mtime -1
我有一个文件 a.dat,大小为 1GB,位于磁盘上。出于性能原因,我重用了这个文件并根据需要简单地覆盖它的内容,而不是创建一个新文件并让它增长(每个增长操作都必须更新它在 inode 中的大小)。
我在这里面临一个棘手的情况。我有一个基于 java 的应用程序,它试图通过 scp 远程机器复制某些文件。在执行这些任务时,我从应用程序端发现以下错误消息。 scp protocol error mt
我很清楚能够执行 find myfile.txt -mtime +5 来检查我的文件是否超过 5 天。但是我想在 myfile.txt 的天数中获取 mtime 并将其存储到变量中以供进一步使用。我该
如何从 Node.js 中找出系统的 mtime 分辨率? 我为什么问 在 Node.js 中,fs.watch 有时会发出重复的 change 事件。为了避免采取多余的操作,通常使用这样的代码(来自
我有一个大小为 550x128 的数组。我将它保存在一个 .mat 文件中并再次加载它以在另一个函数中使用它。 save('c:\\coeffs2.mat', 'descr2'); des2=load
当我使用 Files.getLastModifiedTime 从 Java 读取文件的 mtime 时,返回值被截断为整秒。我知道这适用于其他系统以获取毫秒分辨率的时间,那么我的有什么不同? 这是一个
当我使用 Files.getLastModifiedTime 从 Java 读取文件的 mtime 时,返回值被截断为整秒。我知道这适用于其他系统以获取毫秒分辨率的时间,那么我的有什么不同? 这是一个
更新 下面的 bash 命令行似乎表明它不是 R 问题(玩一下 sleep 看看它只会在每秒 0.43 和 0.93 后更新)。 (所以我更改了问题标签。) touch tmp.txt;stat tm
随着git-restoremtime脚本可以根据提交消息中的日期修改从 git 存储库中 check out 的文件的修改时间。 但是,如何使目录的 mtime 看起来直观、确定且一致? 我认为将每个
我是一名优秀的程序员,十分优秀!