22 lines
		
	
	
		
			765 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			765 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import fs from '@ohos.file.fs';
 | |
| 
 | |
| 
 | |
| export function delLog(offset: number) {
 | |
|   try {
 | |
|     const path = "/mnt/hmdfs/100/account/device_view/local/files/duolun/logs"
 | |
|     const list = fs.listFileSync(path)
 | |
|     const now = new Date().getTime()
 | |
|     list.forEach(filename => {
 | |
|       const year = Number(filename.split("_")[0])
 | |
|       const month = Number(filename.split("_")[1]) - 1
 | |
|       const date = Number(filename.split("_")[2])
 | |
|       const fileDate = new Date(year, month, date).getTime()
 | |
|       if (now - fileDate >= offset * 24 * 60 * 60 * 1000) {
 | |
|         fs.rmdirSync(path + "/" + filename)
 | |
|         console.log("lixiao delete log success path: ", path + "/" + filename)
 | |
|       }
 | |
|     })
 | |
|   } catch (e) {
 | |
|     console.log("lixiao delete log error", JSON.stringify(e))
 | |
|   }
 | |
| } |