由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教如何通过FILE指针删除文件?
相关主题
mutex一问只有executable能debug吗?
准备面试一个java-based position,有什么书推荐一下?有必要学一学MFC吗?
How to compile multiple c files into one obj file?初学者问几个C的问题
WIN32下怎么转文件名从ANSI到UNICODE ?c# for Linux: does it work well ? (转载)
Recommend a C++ IDE?waiting for N condition variables in linux
About command line in C++100伪币答谢Linux/Unix编程问题 (转载)
关于程序必须支持win and linux, 可不可以用class而不是#ifdef WIN32 ?programming windows求教
请教高手:Win32 编程还有用吗?在visual C++ 程序里播放mp3
相关话题的讨论汇总
话题: file话题: linux话题: 指针话题: unix话题: delete
进入Programming版参与讨论
1 (共1页)
o*****e
发帖数: 379
1
只找到remove函数删数,但是参数是文件名。如果一个FILE指针已经打开了文件,如何
获得其打开的文件的名字呢?
或者有什么函数以FILE指针为参数删除文件?
因为是在别人的大project里面改,所以自己定义结构保存指针和文件名的pair会比较
困难。
谢谢。
m*****e
发帖数: 4193
2
In general, you can't. On Linux, you can access /proc/self/fd/x. But if you
ask this question, there is something wrong with your design.

【在 o*****e 的大作中提到】
: 只找到remove函数删数,但是参数是文件名。如果一个FILE指针已经打开了文件,如何
: 获得其打开的文件的名字呢?
: 或者有什么函数以FILE指针为参数删除文件?
: 因为是在别人的大project里面改,所以自己定义结构保存指针和文件名的pair会比较
: 困难。
: 谢谢。

l*****c
发帖数: 1153
3
This is defnitely the safe solution. And in cases not feasible. If other
process opens the same file, you may not be able to delete it.

you

【在 m*****e 的大作中提到】
: In general, you can't. On Linux, you can access /proc/self/fd/x. But if you
: ask this question, there is something wrong with your design.

m*****e
发帖数: 4193
4
You can always delete the file. Other processes can still access it if they
already opened it. In some Unix systems (including maybe the latest Linux
kernel), there is a revoke call that closes all open file descriptors too.

【在 l*****c 的大作中提到】
: This is defnitely the safe solution. And in cases not feasible. If other
: process opens the same file, you may not be able to delete it.
:
: you

l*****c
发帖数: 1153
5
This is true on Linux/Unix but not on all platforms, i.e. on Windows
platform, you can't delete a file if it is open.

they

【在 m*****e 的大作中提到】
: You can always delete the file. Other processes can still access it if they
: already opened it. In some Unix systems (including maybe the latest Linux
: kernel), there is a revoke call that closes all open file descriptors too.

x****u
发帖数: 44466
6
严格的说,Win32 API DeleteFile的实现就是在打开文件句柄的情况下设置文件属性为
关闭时删除的。

【在 l*****c 的大作中提到】
: This is true on Linux/Unix but not on all platforms, i.e. on Windows
: platform, you can't delete a file if it is open.
:
: they

1 (共1页)
进入Programming版参与讨论
相关主题
在visual C++ 程序里播放mp3Recommend a C++ IDE?
数据库能用来存储文件吗?About command line in C++
再来问个蠢问题关于程序必须支持win and linux, 可不可以用class而不是#ifdef WIN32 ?
请问怎么快速的判断一个文件是否存在in c, unix请教高手:Win32 编程还有用吗?
mutex一问只有executable能debug吗?
准备面试一个java-based position,有什么书推荐一下?有必要学一学MFC吗?
How to compile multiple c files into one obj file?初学者问几个C的问题
WIN32下怎么转文件名从ANSI到UNICODE ?c# for Linux: does it work well ? (转载)
相关话题的讨论汇总
话题: file话题: linux话题: 指针话题: unix话题: delete