Solved

xp_cmdshell

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 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

23 Experts available now in Live!

Get 1:1 Help Now