"feat: 同步功能增强与配置优化,支持多类型同步及日志分级"
This commit is contained in:
@@ -1,11 +1,26 @@
|
||||
import fs from 'fs';
|
||||
export const fileIsExist = (filePath: string, isFile = false) => {
|
||||
import fs from 'node:fs';
|
||||
|
||||
export const fileIsExist = (filePath: string) => {
|
||||
try {
|
||||
// 检查文件或者目录是否存在
|
||||
fs.accessSync(filePath, fs.constants.F_OK);
|
||||
if (isFile) {
|
||||
fs.accessSync(filePath, fs.constants.R_OK);
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
export const pathExists = (path: string, type?: 'file' | 'directory') => {
|
||||
try {
|
||||
// 检查路径是否存在
|
||||
fs.accessSync(path, fs.constants.F_OK);
|
||||
|
||||
// 如果需要检查类型
|
||||
if (type) {
|
||||
const stats = fs.statSync(path);
|
||||
if (type === 'file' && !stats.isFile()) return false;
|
||||
if (type === 'directory' && !stats.isDirectory()) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user