I wrote this basic VBScript sample to delete old .bak files from a particular folder if its older than X number of days.
'============================== 'Remove old backups 'http://gordondurgha.com '============================= 'Definitions iDaysOld = 3 strExtension = ".bak" sDirectoryPath = "D:\MSSQL\Backups\" Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(sDirectoryPath) Set oFileCollection = oFolder.Files 'Walk through each file in this folder collection. For each oFile in oFileCollection If oFile.DateLastModified < (Date() - iDaysOld) Then If Right(UCase(oFile.Name), Len(strExtension)) = UCase(strExtension) Then oFile.Delete(True) End If End If Next 'Clean up Set oFSO = Nothing Set oFolder = Nothing Set oFileCollection = Nothing Set oFile = Nothing
This is a sample code for C# to read up an excel file and return the results in a CSV format using the Koogra library.
// This example shows how to read and excel file using the Koogra library (http://sourceforge.net/projects/koogra/) // Supports .xls and .xlsx example public static string ReadExcelContent(string filePath) { uint rowNum = 0; uint colNum = 0; var data = new StringBuilder(); try { Net.SourceForge.Koogra.IWorkbook wb; string fileExt = Path.GetExtension(filePath); if (string.IsNullOrEmpty(fileExt)) { throw new Exception("File extension not found"); } if (fileExt.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)) { wb = Net.SourceForge.Koogra.WorkbookFactory.GetExcel2007Reader(filePath); } else if(fileExt.Equals(".xls", StringComparison.OrdinalIgnoreCase)) { wb = Net.SourceForge.Koogra.WorkbookFactory.GetExcelBIFFReader(filePath); } Net.SourceForge.Koogra.IWorksheet ws = wb.Worksheets.GetWorksheetByIndex(0); for (uint r = ws.FirstRow; r <= ws.LastRow; ++r) { Net.SourceForge.Koogra.IRow row = ws.Rows.GetRow(r); if (row != null) { string lineEnding; for (uint colCount = ws.FirstCol; colCount <= ws.LastCol; ++colCount) { string cellData = string.Empty; if (row.GetCell(colCount) != null && row.GetCell(colCount).Value != null) { cellData = row.GetCell(colCount).Value.ToString(); } if (colCount == ws.LastCol) lineEnding = Environment.NewLine; else lineEnding = "\t"; //tab data.Append(string.Concat(cellData, lineEnding)); } } } } catch (Exception ex) { Exception exception = ex; exception.Source = string.Format("Error occured on row {0} col {1}", rowNum, colNum); throw ex; } return data.ToString(); }