How to get list of all Folder in network sharing path using SQL Server.

   IF OBJECT_ID('tempdb..#TempTableName') IS NOT NULL
    DROP TABLE #TempTableName ;

   CREATE TABLE #TempTableName
    (
      id INT IDENTITY(1, 1) ,
      subdirectory NVARCHAR(512) ,
      depth INT
    ) ;

   INSERT   #TempTableName
            ( subdirectory
                       
            )
            EXEC MASTER.dbo.xp_cmdshell 'dir DriveName:\  /b /o:n /ad'
   IF NOT EXISTS ( SELECT   1
                   FROM     #TempTableName )
    BEGIN
        EXEC XP_CMDSHELL 'net use DriveName: \\ServerName\DriveName /user:domain\USERNAME PASSWORD'---code for Mapping drive in local Pc
    END

    

Post a Comment

0 Comments