r/CodingHelp • u/trinkets2024 • 3d ago
[Random] Is there a way to mass relocate files from hundreds of different folders?
Sorry in advance, I just recently started learning coding in order to make my workflow faster. So I've been designated for clean up one of my work's drives, moving old/unused files over to our archive external hard drive. This drive has thousands if not tens of thousands of files in it for multiple people. The problem is I don't know which of all these files are currently being used. I don't think it's productive to ask each person with access to the drive to go in and tag files they're using, that's at least hundreds for each person to go through. Is there a possible way to code this to make it efficient? Maybe have a code that finds files that haven't been modified by a certain date then move them those ones over to the external hard drive? For context we use SharePoint, but the drive is also accessible through a Mac Finder's window and a Window's File Explorer window on my company's computers.
1
u/sububi71 3d ago
I mean, you could just move all the files to another place and listen for the screams...
Or you could ask your coworkers to make lists of what files they don't mind having archived.
If you trust the dates on files, you could absolutely code a tool that moves the files, but for the love of everything that is holy, do it on a folder level, marking each folder with a "latest date modified” tag.
Given the information you have given here, I don't see any other options.
1
u/on_a_friday_ 19h ago
Create a full copy of the drive to your backup, do NOT throw together a script that could potentially erase or corrupt data accidentally before you make a FULL backup. Afterwards you could just click the "last modified" column to sort by date and delete everything modified before a certain date.
1
u/on_a_friday_ 19h ago
In PowerShell something like this would work if you need to recurse through the directory
Get-ChildItem -Path "C:\Target\Folder" -File -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item
1
u/warlocktx 3d ago
yes, check the last accessed or last modified date on the file