Saddamhusen Uadanwala

Saddamhusen Uadanwala

  • NA
  • 223
  • 166.5k

List of file using 'xp_cmdshell' path more then 128 char

Nov 23 2016 2:23 AM
I am trying to get list of file in a directory using sql server path having more then 128
character is not working.
  1. DECLARE  
  2. @FilePath varchar(256)='D:\...',--replace your path with a length more then 128 char  
  3.   
  4. @SourceFiles varchar(100)='Test123456789*.txt',  
  5. @Query varchar(1000)  
  6.   
  7. If Object_Id('tempdb.dbo.#FirstTable'Is NULL  
  8. CREATE TABLE #FirstTable (Name varchar(256))  
  9.   
  10. SET QUOTED_IDENTIFIER ON  
  11. SET @Query ='master.dbo.xp_cmdshell "dir '+ @FilePath + '\' + @SourceFiles +' /b"'  
  12.   
  13. INSERT #FirstTable exec (@Query)  
  14. select * from #FirstTable  
  15.   
  16. truncate table #FirstTable  

Answers (1)