July 18, 2005 at 2:36 pm
Hey all, is their a way to delete flat files on a local drive through T-SQL? I need to remove all files at "0" bytes.
I thought I'd ask here first prior to going the batch file route.
Thanks.
July 18, 2005 at 2:57 pm
xp_cmdshell can be used to execute dos commands.
Regards,
gova
July 26, 2005 at 7:56 am
And:
--------------------------------------------------------------------------------------------------------
-- CREATE TEMPORARY TABLE TO STORE INFORMATION ABOUT FILES
--------------------------------------------------------------------------------------------------------
Create table #FileInfo
(
AltName NVARCHAR(20) -- Alternative name
,FileSize NVARCHAR(11) -- Size of file (bytes)
,CrDate NVARCHAR(8) -- File creation date (YYYYMMDD)
,CrTime NVARCHAR(6) -- Time or file creation (HHMMSS)
,LastWriteDate NVARCHAR(8) -- Date the file was last modified (YYYYMMDD)
,LastWriteTime NVARCHAR(6) -- Time the file was last modified (HHMMSS)
,LastAccessDate NVARCHAR(8) -- Date the file was last accessed (? Note: NOT opened) (YYYYMMDD)
,LastAccessTime NVARCHAR(6) -- Time the file was last accessed (? Note: NOT opened) (YYYYMMDD)
,Attributes NVARCHAR(11) -- BITMASK of File Attributes
)
-------------------------------------------------------------------------------
-- Get File List of files to copy
-------------------------------------------------------------------------------
SET @ExecuteCommand = 'DIR "' + @SourceDirectory_WithEndingSlash + @SourceFile_Pattern + '" /b'
/* Return Code Values of xp_cmdshell: 0 (success) or 1 (failure) */
INSERT INTO #FilesToCopy EXECUTE @ExecutionResult = master.dbo.xp_cmdshell @ExecuteCommand
And then you could cursor through your files calling this:
-- Retrieve file details for the file for later addition to the FileDetails table
INSERT INTO #FileInfo EXECUTE master.dbo.xp_getfiledetails @FileToCheck
//Hanslindgren
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply