虚拟方法
GioFiledelete_file
声明 [源码]
gboolean
delete_file (
GFile* file,
GCancellable* cancellable,
GError** error
)
描述 [源码]
删除文件。如果文件是目录,并且为空,则将删除。这与 g_unlink() 的语义相同。
如果 file 不存在,将返回 G_IO_ERROR_NOT_FOUND。这允许在删除时避免 检查到使用的时间竞争。
g_autoptr(GError) local_error = NULL;
if (!g_file_delete (my_file, my_cancellable, &local_error) &&
!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
// deletion failed for some reason other than the file not existing:
// so report the error
g_warning ("Failed to delete %s: %s",
g_file_peek_path (my_file), local_error->message);
}
如果 cancellable 不是 NULL,则可以通过在另一个线程中触发可取消对象来取消操作。如果操作被取消,将返回错误 G_IO_ERROR_CANCELLED。
参数
cancellable-
类型:
GCancellable可选的
GCancellable对象,NULL表示忽略。此参数可以为 NULL。数据由方法调用者拥有。 error-
类型:
GError **一个可恢复错误的返回位置。
此参数可以为 NULL。如果返回位置不是 NULL,则必须将其初始化为一个NULL的GError。如果没有错误,虚拟函数将保留此参数初始化为 NULL。如果发生错误,则将参数设置为一个新的 GError;调用者将接管数据的使用,并负责释放它。