我正在使用以下脚本代码,但它不起作用。
DECLARE @TenantId UNIQUEIDENTIFIER ='A79ED820-2E5E-4A9D-B930-B7597DC97081'
DECLARE @BusinessName VARCHAR(200)
declare @line varchar(255) =''
declare @path varchar(255)=''
declare @command varchar(255)=''
DECLARE @folderSizeGB decimal (16,8) = 0
DECLARE @AttachmentDiscSpaceUsed decimal (16,8) = 0
-- 用于计算文件夹大小的代码(以 GB 开头为单位)
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
drop table #temp
create table #temp (line varchar(255))
set @path = '\ewp-dev18\c$\Attachments\' + CONVERT(varchar(50),@tenantId)
set @command = 'dir "' + @path +'"'
insert into #temp
exec master.dbo.xp_cmdshell @command
select @line=
ltrim(replace(substring(line, charindex(')', line)+1,
len(line)), ',', ''))
from #temp where line like '%File(s)%bytes'
SET @line=
(Case WHEN @line IS NULL or @line ='' THEN '0' ELSE @line END)
set @folderSizeGB = Cast(Replace(@line,'bytes', '') as decimal)/1073741824
if (@folderSizeGB is null )
set @folderSizeGB =0
SET @AttachmentDiscSpaceUsed = @folderSizeGB
SET @path=''
SET @command=''
SET @line=0
-- Drop #temp table
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
drop table #temp
-- 用于计算文件夹大小的代码(以 GB END 为单位)
请帮忙..提前感谢
未经过测试,但您的路径正在本地查找远程计算机?
set @path = '\ewp-dev18\c$\Attachments\' + CONVERT(varchar(50),@tenantId)
应该是
set @path = '\\ewp-dev18\c$\Attachments\' + CONVERT(varchar(50),@tenantId)
您还应该包括您收到的错误消息。