0
无法检索文件夹中pdf文件的大小,下面的代码返回表中的空列,我也想知道是否可以存储文件名和大小都在一张表中。无法检索文件夹中的pdf文件的大小
Create table #PDFFiles
(
PDFFile varchar(300)
)
Declare @param as varchar(100)
Declare @Path as varchar(1000)
Declare @PreparedBatch as Nvarchar(max);
Set @PreparedBatch =
'DECLARE @pdf pdf
SELECT @pdf = CAST(BulkColumn AS pdf)
FROM OPENROWSET(BULK ''?'', SINGLE_BLOB) AS x
INSERT dbo.PDFDocument (PDFdoc)
SELECT @pdf;';
Set @Path = 'C:\dump\'
Set @param = 'dir ' + @Path + '*.pdf /b'
Insert into #PDFFiles
Exec master..xp_cmdshell @param
Update #PDFFiles Set PDFFile = @Path + PDFFile
While Exists(select * from #PDFFiles where PDFFile is not null)
Begin
Declare @CurrentFile Table (PDFFile varchar(300));
Delete Top (1) from #PDFFiles
OUTPUT DELETED.PDFFile INTO @CurrentFile
Where PDFFile is not null
Declare @Batch as Varchar(max)
Select @Batch = Replace(@PreparedBatch,'?',PDFFile) from @CurrentFile
Exec (@Batch)
Delete from @CurrentFile
End
这是运行该代码时,我正在错误
Column, parameter, or variable #1: Cannot find data type pdf.
Parameter or variable '@pdf' has an invalid data type.
当我将其更改为varbinary时,出现此错误 类型pdf不是定义的系统类型。 – Zack
你在多个位置有这样的定义:'SELECT @pdf = CAST(BulkColumn AS pdf)' –