Follow me on twitter @yodasmydad
Ahhhh #Fringe can't finish like that!! Latest Tweet:

Hey I'm Lee. My blog was put up to house my strange thoughts, ramblings, nuggets of information I can refer back to and document my learning curves on new dev stuff like Umbraco v5 and other .NET related things.

All thoughts and comments on here are my own, and in no way reflect my employer - I also take no responsibility for spelling, grammar or terminology, so read at your own risk!

Blogs I Read

Sites I Like

Useful Batch Files

I have been having a bit of a batch file session recently, never had much need for them but decided to have a go at creating batch files to perform various tasks to help me save time - I thought I would dump some of them on here as they might be useful to other people, also to remind myself of certain syntax.

To use these below, you just need to open up notepad copy and paste the code into the text document and save with a .bat extension

Delete Log Files Over 30 Days Old

Kind of speaks for itself… This little gem will go off and delete all log files that are over 30 days old, it works on nested folders too - Just change the file path to the location of your log files.  If you want to use this for something else and not just log files, you can always change the file type to delete from *.log to anything… Say *.bak for DB backups. 

If you want to increase the time frame from 30 days to say 60 days, just change the part where it has -30 to (Obviously) -60.

forfiles.exe /p C:\inetpub\logs\LogFiles /s /m *.log /d -30 /c "cmd /c del @file"

Delete All Files Of A Specific Type

I was using the above batch file to delete old MSSQL backups which were no longer needed, but for reasons I won't go into I couldn't use this anymore due to an offsite backup issue - In the end I just needed a plain and simple way of deleting all files of a specific type from a specific folder when triggered by Task manager. And its VERY simple to do this, again just change the file path to your folder location and change the file type you want to delete.

del "D:\db-backup\*.bak"

Fast FTP

Last thing I needed to do was schedule and FTP upload using task manager, and when triggered it just either uploaded or downloaded all files.  Again this is really easy, and I have found it VERY fast - The batch file just consists of the following line.

ftp -s:FTP.txt

Now you need to make sure you have a text file called FTP.txt in the same location as the batch file you created above - In the FTP.txt file you need to add the following, obviously swap out your ftp IP address or domain, user name and password to yours!! Also change the folder location

open 192.192.192.195
YourFTPUsername
YourFTPPassword
lcd C:\Users\Lee\Desktop\ftptest
prompt
mput *.*
quit

Also you can change mput *.* to mget *.* which will download all the files instead of uploading..

mput *.* = Upload

mget *.* = Download

Back to top