如何使用C语言进行文件的重命名及删除操作?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用C语言进行文件的重命名及删除操作?相关的知识,希望对你有一定的参考价值。
参考技术A 在<stdio.h>包里有两个函数可以满足你的要求:注意,这两个函数操作的文件必须要关闭,否则会执行失败,如果失败,执行完成后可以通过比较errno的值来确定失败原因.
重命名:
int rename(const char *oldname, const char *newname);
参数解释:
oldname:原文件名
newname:新文件名(可以指定全局路径来移动文件)
返回值:
0:成功
-1:失败,并将全局变量errno置为错误码
删除:
int remove(const char *filename);
参数解释:
filename:要删除的文件名
返回值:
0:成功
-1:失败,并将全局变量errno置为错误码本回答被提问者采纳
ArcPy 重命名拷贝删除图层
使用Python脚本进行图层的重命名拷贝及删除,并在过程中利用logging进行日志记录。
附上Python代码:
1 # -*- coding: utf-8 -*- 2 # nightroad 3 import sys 4 import arcpy 5 import logging 6 7 logging.basicConfig(level=logging.DEBUG, 8 format=‘%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s‘, 9 datefmt=‘%a, %d %b %Y %H:%M:%S‘, 10 filename=‘log.txt‘, 11 filemode=‘a‘) 12 path = r"C:Users ightroadAppDataRoamingESRIDesktop10.0ArcCatalog est.sdeTEST" 13 arcpy.env.workspace = path 14 try: 15 print "delete line_1" 16 logging.info("delete line_1") 17 arcpy.Delete_management("line_1") 18 print "delete point_1" 19 logging.info("delete point_1") 20 arcpy.Delete_management("point_1") 21 except Exception as e: 22 print("no data or delete error!",e) 23 logging.warning("no data or delete error!") 24 try: 25 print "rename line" 26 logging.info("rename line") 27 arcpy.Rename_management("line", "line_1") 28 print "rename point" 29 logging.info("rename point") 30 arcpy.Rename_management("point", "point_1") 31 try: 32 print "copy point" 33 logging.info("copy point") 34 arcpy.Copy_management(r"E:TEST.gdbTESTpoint","point") 35 print "copy line" 36 logging.info("copy line") 37 arcpy.Copy_management(r"E:TEST.gdbTESTline","line") 38 try: 39 print "delete line_1" 40 logging.info("delete line_1") 41 arcpy.Delete_management("line_1") 42 print "delete point_1" 43 logging.info("delete point_1") 44 arcpy.Delete_management("point_1") 45 except Exception as e: 46 print("delete error!",e) 47 logging.error("delete error!") 48 except Exception as e: 49 print("copy error!",e) 50 logging.error("copy error!") 51 except Exception as e: 52 print("rename error!",e) 53 logging.error("rename error!")
以上是关于如何使用C语言进行文件的重命名及删除操作?的主要内容,如果未能解决你的问题,请参考以下文章