harry 3 роки тому
батько
коміт
fe1ae73ae5

+ 5 - 0
BFCommonKit/Classes/BFUtility/PQBridgeObject.h

@@ -22,6 +22,11 @@ NS_ASSUME_NONNULL_BEGIN
 + (CGFloat)getPhoneDiskFreeSize;
 
 + (NSString *)base64Md5ForFilePath:(NSString *)filePath;
+
+// 对文件重命名
++ (NSString *)p_setupFileRename:(NSString *)filePath;
+
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 40 - 0
BFCommonKit/Classes/BFUtility/PQBridgeObject.m

@@ -133,5 +133,45 @@ int32_t const CHUNK_SIZE = 8 * 1024;
 
 }
 
+/**
+ 对文件重命名
+
+ @param filePath 旧路径
+ @return 新路径
+ */
++ (NSString *)p_setupFileRename:(NSString *)filePath {
+    
+    NSString *lastPathComponent = [NSString new];
+    //获取文件名: 视频.MP4
+    lastPathComponent = [filePath lastPathComponent];
+    //获取后缀:MP4
+    NSString *pathExtension = [filePath pathExtension];
+    //用传过来的路径创建新路径 首先去除文件名
+    NSString *pathNew = [filePath stringByReplacingOccurrencesOfString:lastPathComponent withString:@""];
+    //然后拼接新文件名:新文件名为当前的:年月日时分秒 yyyyMMddHHmmss
+    NSString *moveToPath = [NSString stringWithFormat:@"%@%@.%@",pathNew, [self htmi_getCurrentTime], pathExtension];
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    //通过移动该文件对文件重命名
+    BOOL isSuccess = [fileManager moveItemAtPath:filePath toPath:moveToPath error:nil];
+    if (isSuccess) {
+        NSLog(@"rename success");
+    }else{
+        NSLog(@"rename fail");
+    }
+    
+    return moveToPath;
+}
+
+/**
+ 获取当地时间
+ 
+ @return 获取当地时间
+ */
++ (NSString *)htmi_getCurrentTime {
+    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+    [formatter setDateFormat:@"yyyyMMddHHmmss"];
+    NSString *dateTime = [formatter stringFromDate:[NSDate date]];
+    return dateTime;
+}
 
 @end