Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Get contents of a directory/share to a table

By Keith Henry,

Following on from todays QOD (on xp_cmdshell permissions) I thought this might be useful.

Takes a directory or UNC path and returns the contents as a table. 

eg:
exec sp_getdir '\\mypc\c$'

returns:
datestring timestring directory   filesize    nameoffile
---------- ---------- ----------- ----------- ----------------------
18/07/2003 10:45      1           NULL        Documents and Settings
18/07/2003 11:02      1           NULL        Program Files
10/07/2003 17:03      1           NULL        WINNT

It handles the error mentioned in the QOD with a useful message.

eg:
exec sp_getdir '\\mypc\c$' (where I'm not sysadmin)

might return:
Current user's login is NOT a member of the sysadmin role
Non sysadmin executions of xp_cmdshell currently run as: MYDOMAIN\AUSER
You can change this with xp_sqlagent_proxy_account N'SET', , ,

Total article views: 236 | Views in the last 30 days: 1
 
Related Articles
FORUM
ARTICLE

Top 100 things you don't want the sysadmin to say

Hopefully you never hear any of these from your sysadmin...

FORUM

Windows AD Group >> Sysadmins SQL Server 2005

Question Windows AD group added into sysadmins - authenticating seems funny

BLOG

Who are the sysadmins in this sql server?

Here’s a quick query that you can run to find out the users with sysadmin fixed server role. Sysadmi...

FORUM

Removing SysAdmin role for login

Removing SysAdmin role for login

Tags
miscellaneous    
t-sql    
 
Contribute