Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

xp_cmdshell

Posted on 2004-10-20
4
Medium Priority
?
748 Views
Last Modified: 2008-03-06
I want to change directories using xp_cmdshell and then select the file names in a directory.  What is the syntax for this?
0
Comment
Question by:wordtool
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
MartinCMS earned 80 total points
ID: 12363024
try.....

EXEC master..xp_cmdshell 'cd H:\path\ '
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 12363033
2 ways
either put all your commands in a bat file and execute that
or insert the output of a dir command into a temp table and then generate/process your commands from that

e.g.
create table #temp (id int identity(1,1),Dataline varchar(255))
declare @NumRows int,@Loop
Insert into #temp
   (dataline)
 exec master.dbo.xp_cmdshell "Dir C:\xyz\abc"
set @numrows=@@rowcount
set @loop=1
while @loop < @numrows
begin
...
set @loop=@loop+1
end
.




0
 

Author Comment

by:wordtool
ID: 12363065
MartinCMS, you giving me "cd' but not "dir".

Lowfatspread, I'll try it...
0
 

Author Comment

by:wordtool
ID: 12363228
MartinCMS, I'm sorry this does "cd" and "dir".

Lowfatspread, please look out for my next question.  What I'm looking for is more of what you are providing, thank you.  I need just the file/folder names without the attributes and the records without the Drive volume information.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question