24 August 2022

How to Obtain List of Files in a Folder from SQL Query

USE master; 

GO


-- To allow advanced options to be changed.

EXECUTE sp_configure 'show advanced options', 1; 

GO 


-- To update the currently configured value for advanced options. 

RECONFIGURE; 

GO


-- To enable the feature. 

EXEC sp_configure 'xp_cmdshell', 1; 

GO 


-- To update the currently configured value for this feature. 

RECONFIGURE;


USE MyDATABASE;

GO


CREATE TABLE zListFileName(NamaFile VARCHAR(300));

GO


INSERT INTO zListFileName

EXEC xp_cmdshell 'dir /B "D:\"';

GO


SELECT * FROM zListFileName

GO

No comments:

Post a Comment