Existing Folder | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Existing Folder

First , best wishes in this year.
Help me please .. How can I find out if some folder on pc is exist ? Thanks , Lubo
Run this EXEC Master..xpcmdShell ‘Dir folder_path’ Madhivanan Failing to plan is Planning to fail
Check this SP
create procedure sp_FolderFileExist
@File varchar(1000) , –The folder or file name.
@Switch bit –0 = Folder; 1 = File
as
–Variables
declare @rtn int
select @rtn = 0 –Executed with no errors.
–Create a temp table.
create table #FolderFileExists
(
[File Exists] int
, [File is a Directory] int
, [Parent Directory Exists] int
)
insert #FolderFileExists exec master..xp_FileExist @File if not exists
( select * from #FolderFileExists
where
case @Switch when 0 then [File is a Directory]
when 1 then [File Exists]
end = 1
)
begin
select @rtn = -1
end
Quit:
return @rtn GO
—————————————-
http://spaces.msn.com/members/dineshasanka

Thnaks for answer .
Dineshasanka – when i set set @File =’d: mp’ OR ‘d: mpX’
set @Switch =0 Drive d: … is existing
Directory ‘d: mp’ … is existing , ‘d: mpNOT’ … not exist exec sp_FolderFileExist ‘D:TmpNOT’ , 0
exec sp_FolderFileExist ‘D:Tmp’ , 0
Procedure return always values
FileExist=0
File is a Directory=0
Parent Directory Exists=1
Did you try this? EXEC Master..xpcmdShell ‘Dir ‘D:Tmp’
Madhivanan Failing to plan is Planning to fail
Yes , but result is same.

I tryied with my code it it give me correct results —————————————-
http://spaces.msn.com/members/dineshasanka

I want to subscribe here more about it . But i get back error always when i press SUBMIT REPLY.
Part I
declare @cesta as varchar(255)
set @cesta=’dir D:Tmp’
create table testDir (output varchar(255))
insert testDir

Part II
EXEC Master..xp_____cmdShell @cesta
REsult is
1 The system cannot find the file specified.
2 NULL But D:Tmp is exist . BTW – name of xp__procedure what i call is xp__cmdShell ( in statement is _ only 1) Lubo
Did you try with other folder?
Because what you write works.
Luis Martin
Moderator
SQL-Server-Performance.com Although nature commences with reason and ends in experience it is necessary for us to do the opposite, that is to commence with experience and from this to proceed to investigate the reason.
Leonardo Da Vinci Nunca esperes el reconocimiento de tus hijos, eso ocurrirá luego de tu muerte
All postings are provided “AS IS” with no warranties for accuracy.
Is it in the SQL Server system, or somewhere else? Madhivanan Failing to plan is Planning to fail
Luis , When I replace name of folder (now is name foto) (sample )
declare @cesta as varchar(255)
set @cesta=’dir D:foto’
drop table testDir
create table testDir (output varchar(255))
insert testDir
EXEC Master..xp__cmdShell @cesta Result is
1 The system cannot find the file specified.
2 NULL You wrote that my code is good. Maybe I am wrong . Maybe I am waiting something but this code can’t return it. What value (rows )is returned on your PC ?

I repeat Is it in the SQL Server system, or somewhere else? Madhivanan Failing to plan is Planning to fail
I am working with MS Sql server 2000. In stored procedure I need to find out if some specific folder exist on drive .
quote:Originally posted by luma Luis , When I replace name of folder (now is name foto) (sample )
declare @cesta as varchar(255)
set @cesta=’dir D:foto’
drop table testDir
create table testDir (output varchar(255))
insert testDir
EXEC Master..xp__cmdShell @cesta Result is
1 The system cannot find the file specified.
2 NULL You wrote that my code is good. Maybe I am wrong . Maybe I am waiting something but this code can’t return it. What value (rows )is returned on your PC ?
The account under which SQL Server is running, and/or the account under which the T-SQL code is executed, must have permission to browse the path. Also, does the D: drive exist on the SQL Server machine? And if it is a mapped network drive, then is it mapped to the same location that you think it is?
So , my SQL run on server not on PC. And drive D is drivo on local pc. Now I understood – it’s a problem .
quote:Originally posted by luma So , my SQL run on server not on PC. And drive D is drivo on local pc. Now I understood – it’s a problem .

ah! yes those codes gives information about the server machine not the local pc —————————————-
http://spaces.msn.com/members/dineshasanka

Now it’s ok, thanks, lubo
]]>