Solved

xp_cmdshell

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 setup several different housekeeping processes for a SQL Server.

828 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