Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

xp_cmdshell

Posted on 2004-10-20
4
Medium Priority
?
734 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

730 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