Home > Ask the SQL Server Experts > Archive: Integration Services Questions & Answers > How to find and delete file names
Ask The SQL Server Expert: Questions & Answers
EMAIL THIS

How to find and delete file names

Joe Toscano EXPERT RESPONSE FROM: Joe Toscano

Pose a Question
Other SQL Server Categories
Meet all SQL Server Experts
Become an Expert for this site


Expert advice on database development
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 01 June 2006
I am trying to get a list of file names with .bak and .trn extensions from a specific path (say D: Test folder), which contains files. I want to search and delete the file names with .bak or .trn extensions with old dates. How is this done in T-SQL or Data Transformation Services (DTS)?

>
You may consider working with files and the FileSystemObject and ActiveX Script Tasks. Here's some sample code:

' Sample code that Copies A File
Option Explicit

Function Main()
 Dim oFSO
 Dim sSourceFile
 Dim sDestinationFile
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 sSourceFile = "C:SourceFile.txt"
 sDestinationFile = "C:DestinationFile.txt"
 oFSO.CopyFile sSourceFile, sDestinationFile
 ' Clean Up
 Set oFSO = Nothing
 Main = DTSTaskExecResult_Success
End Function


' Sample code that Moves a File 
Option Explicit

Function Main()
 Dim oFSO
 Dim sSourceFile
 Dim sDestinationFile
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 sSourceFile = "C:SourceFile.txt"
 sDestinationFile = "C:FolderDestinationFile.txt"
 oFSO.MoveFile sSourceFile, sDestinationFile
 ' Clean Up
 Set oFSO = Nothing
 Main = DTSTaskExecResult_Success
End Function


Here's one that may help you. Check the File Date & Time
Option Explicit


Function Main()
 Dim oFSO
 Dim oFile
 Dim sSourceFile
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 sSourceFile = DTSGlobalVariables("SourceFileName").Value
 Set oFile = oFSO.GetFile(sSourceFile)
 If oFile.DateCreated < Date Then
  Main = DTSTaskExecResult_Success
 Else
  Main = DTSTaskExecResult_Failure
 End If
 ' Clean Up
 Set oFile = Nothing
 Set oFSO = Nothing
End Function


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
Archive: Integration Services
How to convert DTS packages to SSIS and overwrite data
How to migrate DTS to SSIS and deploy SSIS packages
Query to search text in old DTS packages in SQL Server?
Error importing Excel data to SSIS in SQL Server 2005
Delete .bak files automatically with CLR
DTS package designed to overwrite extract.xls
Displaying a SQL Server database report in Excel
Stored procedure practices in SQL Server
Call triggers in a stored procedure
SQL Server permission to create jobs and schedules in SSIS

SQL/Transact SQL (T-SQL)
Using DELETE and TRUNCATE TABLE statements to delete data in SQL Server
SQL language crash course (just enough to be dangerous)
Working with IntelliSense in SQL Server 2008 Management Studio
SQL Server Mailbag: Stored procedures, triggers and SSRS reports
Working with sparse columns in SQL Server 2008
Determining the source of full transaction logs in SQL Server
New GROUP BY option provides better data control in SQL Server 2008
Using the OPENROWSET function in SQL Server
Loading data files with SQL Server's BULK INSERT statement
Importing and exporting bulk data with SQL Server's bcp utility
SQL/Transact SQL (T-SQL) Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
ACID  (SearchSQLServer.com)
Collaboration Data Objects  (SearchSQLServer.com)
commit  (SearchSQLServer.com)
container  (SearchSQLServer.com)
DAO  (SearchSQLServer.com)
fetch  (SearchSQLServer.com)
OLE DB  (SearchSQLServer.com)
query  (SearchSQLServer.com)
SQL  (SearchSQLServer.com)
T-SQL  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



SQL Solutions - SQL Database Design
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts