Command line basics for dummies
July 3, 2011 6:44 AM Subscribe
Need help auto-deleting folders clogging my SSD...
Long story short: I've created a .cmd file to do some daily task manager maintenance on my newly built HTPC (moving recorded tv from the SSD to the external hard drive, etc.), and want to add a line that would delete certain folders from my XBMC cache folder that I've discovered accumulate 10-15 gigs per day.
The folders are usually called rarfolder0001, 0002, etc.
Is there a command line function that would delete those folders (i.e., "del c:\[user name]\appdata\xbmc\cache\rarfolder*\")???
I tried the above and all kinds of variations but could not make it work.
Thanks guys!
Long story short: I've created a .cmd file to do some daily task manager maintenance on my newly built HTPC (moving recorded tv from the SSD to the external hard drive, etc.), and want to add a line that would delete certain folders from my XBMC cache folder that I've discovered accumulate 10-15 gigs per day.
The folders are usually called rarfolder0001, 0002, etc.
Is there a command line function that would delete those folders (i.e., "del c:\[user name]\appdata\xbmc\cache\rarfolder*\")???
I tried the above and all kinds of variations but could not make it work.
Thanks guys!
Be careful deleting files blindly. Even if they're cache files you'll do well to put a delay in place and have your script only delete files older than X days.
Here's another google result that might help you out:
http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days
posted by devbrain at 7:11 AM on July 3, 2011
Here's another google result that might help you out:
http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days
posted by devbrain at 7:11 AM on July 3, 2011
Response by poster: Thanks - does the asterisk function work with rd or rmdir? If not, what's an alternative? I want to be able to delete all folders that begin with a particular string of text (rarfolder0001, rarfolder0002, et al).
posted by BobbyVan at 9:00 AM on July 3, 2011
posted by BobbyVan at 9:00 AM on July 3, 2011
I think RD does not accept wildcards (e.g. *) but this is my pc's day off so I can't check.
Instead, I think you can use something like
for %I in (*) do RD %I
devbrain's stack overflow suggestion looks good
posted by anadem at 10:56 AM on July 3, 2011
Instead, I think you can use something like
for %I in (*) do RD %I
devbrain's stack overflow suggestion looks good
posted by anadem at 10:56 AM on July 3, 2011
Response by poster: anadem, can you explain a bit more about the %I function when you have a chance? the stack overflow isn't what i'm looking for because what i want to remove isn't date specific -- these folders contain full-length avi and mkv videos that were cached for some reason and can be freely deleted.
thanks
posted by BobbyVan at 2:11 PM on July 3, 2011
thanks
posted by BobbyVan at 2:11 PM on July 3, 2011
By the way, when batch-deleting files, it's really valuable to start out by making some test files in a test folder so you can try our different strategies and see if they work, how asterisks behave, etc. Much easier and less scary than testing some code by setting it loose on your "real" folders!
posted by exphysicist345 at 11:50 PM on July 3, 2011
posted by exphysicist345 at 11:50 PM on July 3, 2011
BobbyVan, the %I isn't a function. It's the variable amadem chose to use in the thing that does the real work, the FOR.
Here's some documentation on the FOR command: http://ss64.com/nt/for.html
So, you probably want to do something like:
for /D /R %I in c:\[user name]\appdata\xbmc\cache\rarfolder* do rd %I
The /D will return only folders. The /R will return those directories that are "rooted" in the path you specified.
As exphysicist345 noted, please test this out in some dummy environment before letting loose on your actual directories.
posted by chengjih at 10:36 AM on July 4, 2011
Here's some documentation on the FOR command: http://ss64.com/nt/for.html
So, you probably want to do something like:
for /D /R %I in c:\[user name]\appdata\xbmc\cache\rarfolder* do rd %I
The /D will return only folders. The /R will return those directories that are "rooted" in the path you specified.
As exphysicist345 noted, please test this out in some dummy environment before letting loose on your actual directories.
posted by chengjih at 10:36 AM on July 4, 2011
Response by poster: thanks chengjih - i'll give that a whirl on a few test folders!
posted by BobbyVan at 1:19 PM on July 4, 2011
posted by BobbyVan at 1:19 PM on July 4, 2011
This thread is closed to new comments.
You can also construct fancier loop/find statements, e.g., http://stackoverflow.com/questions/521382/command-line-tool-to-delete-folder-with-a-specified-name-recursively-in-windows.
posted by chengjih at 7:09 AM on July 3, 2011