Listing Files in Hard Disk in SQL Server
Hello everyone,
In this article, I will give information about listing the files in the hard disk in SQL Server.
In SQL Server, in some cases, it may be necessary to list the files in the hard disk.
By using the code below, you can perform the listing of the files in the hard disk.
DECLARE @FolderContents TABLE
(
ID INT IDENTITY,
FileNames VARCHAR(100)
);
INSERT INTO @FolderContents
EXECUTE xp_cmdshell 'dir C:\ /b';
SELECT *
FROM @FolderContents;
When you run the code, you will get a result like the one below.
As you can see, the files in the C folder are listed.
Good luck to everyone in business and life.