Solved

xp_cmdshell

Posted on 2004-10-20
4
657 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 20 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now