October 4, 2010 at 5:44 am
Hi,
How to get the size of the file using sp_OAGetProperty in KB.
i want to find the size of text file.
Thanks,
Pulivarthi
October 4, 2010 at 5:48 am
if the only thing you are after is file size, the DIR command is faster and easier to use to get it; now if you are after information like modified date, version information, and other stuff exposed by the FileSystemObject, sp_OaCreate might work, but there are easier methods via CLR to do that;
CREATE TABLE #Results (txtResult varchar(2000) NULL)
INSERT INTO #Results (txtResult)
--get path and file size information about all files in a given directory
EXEC master.dbo.xp_cmdshell 'DIR D:\*_BACKUP_*.*'
SELECT * FROM #Results
Lowell
October 4, 2010 at 6:10 am
here's a slight modification chopping up the results into file date,filesize and filename:
SELECT
SUBSTRING(txtResult,1,20) AS FileDate,
CASE
WHEN txtResult LIKE '%<DIR>%'
THEN NULL
ELSE LTRIM(RTRIM(SUBSTRING(txtResult,21,18)))
END AS FileSize,
CASE
WHEN txtResult LIKE '%<DIR>%'
THEN NULL
ELSE LTRIM(RTRIM(SUBSTRING(txtResult,40,2000)))
END AS FileName*
FROM #Results
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply