Personal computing discussed

Moderators: SecretSquirrel, just brew it!

 
drfish
Gold subscriber
Gerbil Elder
Topic Author
Posts: 5126
Joined: Wed Jan 22, 2003 7:53 pm
Location: Zeeland, MI

Creating a log of deleted files and their location

Fri Jan 13, 2017 1:37 pm

Oh great developers, please look favorably upon this poor soul.

We're purging a lot of data at work (no, not Enron-style). I'm going to delete a bunch of files with specific extensions, above a specific size, and older than a specific date to reduce our storage footprint. Easy enough so far.

However, now I've been asked to create a log of all the files that we delete and what folder they were in "for future reference" - a reasonable enough request, but one that takes me out of my comfort zone. I found this post that I think is generally what I want - but I just don't have the chops to confidently modify and execute it for my purposes. The most sophisticated batch file I've written in years copies files to a RAM drive before launching my Minecraft server. Can you help a gerbil out with a little forum-based training?
TR BBQ XIV is over.
 
Flying Fox
Gerbil God
Posts: 25417
Joined: Mon May 24, 2004 2:19 am
Contact:

Re: Creating a log of deleted files and their location

Fri Jan 13, 2017 5:41 pm

That linked script looks unfamiliar to you because it is not batch but PowerShell. If learned properly you can definitely do some interesting things with it. You can probably pick it up in an afternoon with some basic PowerShell tutorials on the 'net.

Edit: Do the 3 conditions always go together? Do you need to sort files by directories in the "report", or just a dump of the full paths? Your link is good. Your conditions can be inserted in the Where-Object block, but if you need a bit more fancy condition evaluations, you can write a boolean-returning function and put it in the Where-Object block. Custom formatting can be done by using the Tee-Object cmdlet with the -Variable. This will accumulate an array of the FileInfo objects and after the delete you can do whatever customized formatting with them.
Last edited by Flying Fox on Fri Jan 13, 2017 8:02 pm, edited 1 time in total.
The Model M is not for the faint of heart. You either like them or hate them.

Gerbils unite! Fold for UnitedGerbilNation, team 2630.
 
Usacomp2k3
Gerbil God
Posts: 21674
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL
Contact:

Re: Creating a log of deleted files and their location

Fri Jan 13, 2017 6:44 pm

I start by using something like xcopy to copy the full directory structure with all files. It looks like the /t flag.. It's actually robocopy with the /create flag to copy directory structure and zero-length files.
 
just brew it!
Gold subscriber
Administrator
Posts: 49671
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Creating a log of deleted files and their location

Sat Jan 14, 2017 6:37 am

@Usacomp2k3 -

How does that help create a log of deleted files?

@drfish -

I've been (mostly) out of the Windows world for a while, but the way I'd handle this is to generate a listing of the directory tree pre- and post-deletion, and do a diff. The diff is your log.

Periodically do the directory tree list and save the output, and you have the ability to easily see what files were created/deleted between any arbitrary dates.
Nostalgia isn't what it used to be.
 
SecretSquirrel
Minister of Gerbil Affairs
Posts: 2296
Joined: Tue Jan 01, 2002 7:00 pm
Location: The Colony, TX (Dallas suburb)
Contact:

Re: Creating a log of deleted files and their location

Sat Jan 14, 2017 11:39 am

Generate the report, through whatever tooling you use, then use the report as input to the file deletion. Alternatively, you write the report and delete into a single tool so that a file that matches the criteria is then added to the report and immediately deleted. Anything else will result in files being deleted and not being included in the report.

--SS
 
chuckula
Gold subscriber
Gerbil Jedi
Posts: 1569
Joined: Wed Jan 23, 2008 9:18 pm
Location: Probably where I don't belong.

Re: Creating a log of deleted files and their location

Sat Jan 14, 2017 12:11 pm

If this was Linux I would recommend making a daemon process [or use an existing tool like GAMIN] that monitors the directories of interest using the inotify framework and then make records of deleted files that way.
Under Windows I did find this article about file monitoring programs that might be helpful:
https://www.raymond.cc/blog/3-portable- ... s-changes/
4770K @ 4.7 GHz; 32GB DDR3-2133; GTX-1080; 512GB 840 Pro (2x); Fractal Define XL-R2; NZXT Kraken-X60
--Many thanks to the TR Forum for advice in getting it built.
 
Usacomp2k3
Gerbil God
Posts: 21674
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL
Contact:

Re: Creating a log of deleted files and their location

Sun Jan 15, 2017 5:49 pm

just brew it! wrote:
@Usacomp2k3 -

How does that help create a log of deleted files


It would be a snapshot in time of the files that exist that can be navigated in explorer or whatever people are comfortable with. You could even though the output into a zip file.
 
DragonDaddyBear
Gerbil Elite
Posts: 651
Joined: Fri Jan 30, 2009 8:01 am

Re: Creating a log of deleted files and their location

Sun Jan 15, 2017 7:42 pm

Do yourself a huge favor and learn PowerShell. I can't speak highly enough about how helpful it is.

What you linked is probably pretty close to what you need.  there is a what if switch you can use to test, too. That would help in your testing.
 
drfish
Gold subscriber
Gerbil Elder
Topic Author
Posts: 5126
Joined: Wed Jan 22, 2003 7:53 pm
Location: Zeeland, MI

Re: Creating a log of deleted files and their location

Mon Jan 16, 2017 7:31 am

Thanks for the suggestions guys. I did know that it was PowerShell, not a batch file, I was just using that as a reference point for my current abilities in this arena. If that sounds like the best approach to you all, I'll start playing around with it. I was hoping someone would have a suggestion that worked like a duplicate file checker or something and produced a log automatically just by checking a box before deleting or something. Oh well.
TR BBQ XIV is over.

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest