-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added function to check the size of the user's current dir, exiting i…
…f too large.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export function getDirectorySize(dir) { | ||
let size = 0; | ||
return traverse(dir); | ||
// Helper function to traverse the directory and its subdirectories | ||
function traverse(dirPath) { | ||
// Read the contents of the directory | ||
const files = fs.readdirSync(dirPath); | ||
|
||
// Loop through each file and subdirectory | ||
for (const file of files) { | ||
const filePath = path.join(dirPath, file); | ||
const stats = fs.statSync(filePath); | ||
|
||
// If it's a file, add its size to the total | ||
if (stats.isFile()) { | ||
size += stats.size; | ||
} | ||
// If it's a subdirectory, recursively traverse it | ||
else if (stats.isDirectory()) { | ||
traverse(filePath); | ||
} | ||
if (size>200 *124 *124){ | ||
|
||
return true | ||
} | ||
}return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters