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.

Listing Files in Hard Disk in SQL Server

As you can see, the files in the C folder are listed.

Good luck to everyone in business and life.

165 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!