Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I know if a folder exists
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00962392
Message ID:
01302626
Vues:
8
>>Hello all,
>>
>>I am trying to determine if a folder exist on my server.
>>If the folder exist I would like to rename it.
>>
>>I know I can use the xp_fileexist extended procedure but I do not know how to determined if it is a folder.
>
>See sample code below that shows how you can check for directory existence
CREATE TABLE #temp01 ( FileExists int, IsDirectory int, ParentDir int)
>INSERT INTO #temp01 EXEC master..xp_fileexist 'C:\Program Files'
>SELECT CASE IsDirectory
>	WHEN 1 Then 'Directory Exists'
>	ELSE 'Directory doesn''t Exist or it''s a file' END
>	FROM #temp01
>DROP TABLE #temp01
>
Hi Sergey,

I could not get the syntax right to insert a value and a result of SP. Here is what I've tried and then have to drop table name:
drop table #Stats
if object_ID('Stats') is null
   create table #Stats (Statistics_Name varchar(128), Statistics_Keys varchar(128))

--exec sp_MSforeachtable 
  -- 'insert into #Stats ''?'', execute sp_helpstats ''?'', ''ALL'''
declare @table varchar(128)
declare @cmd varchar(500) 

declare tables cursor for
select table_name from information_schema.tables
   where table_type = 'base table'
open tables
fetch next from tables into @table
while @@fetch_status = 0
begin
  set @cmd = 'insert into #Stats execute sp_helpstats ''' + @table + ''', ''ALL'''
  print @cmd
  --insert into #rowcount exec (@cmd)
  execute (@cmd)
  fetch next from tables into @table
end
CLOSE tables 
DEALLOCATE tables
Would you please help?

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform