如何通过SQL获取本地驱动器上的文本文件的文件大小 [英] How do I get the file size of a text file on my local drive through SQL

查看:60
本文介绍了如何通过SQL获取本地驱动器上的文本文件的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在SQL中检索我的驱动器上存在的文本文件的大小。



我尝试了什么:



我试过openrowset,我的查询就像(从openrowset中选择datalength(bulkcolumn)(批量'C:\ a.txt',single_clob)a )



但是当我提供变量而不是静态路径时,查询不会编译。

I would like to know how to retrieve the size of a text file present on my drive in SQL.

What I have tried:

I have tried openrowset and my query goes like (select datalength(bulkcolumn) from openrowset(bulk 'C:\a.txt', single_clob) a)

But when I supply a variable instead of static path, the query does not compile.

推荐答案

根据上面的建议,我会发布我的提示/解决方案以使球滚动。



Stack有一个很好的xp_cmdshell示例:

[ ^ ]

使用该示例,您首先需要使用sp_configure配置xp_cmdshell,如下所示(如果您没有权限,你需要一个系统管理员或DBA来为你运行它):



Per recommendation above, I'll post my tip/solution to get the ball rolling.

Stack has a nice example of the xp_cmdshell at:
[^]
Using the example you'll first need to configure the xp_cmdshell using sp_configure as shown below (if you don't have permissions, you'll need a System Admin or DBA to run it for you):

Use Master
GO

EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO

EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
GO





现在你可以运行xp_cmdshell了。





Now you can run xp_cmdshell.

EXECUTE master.dbo.xp_cmdshell 'DIR "C:\YourDirectory" /A-D /B'





它很好用。它以熟悉的表格格式显示在结果窗口中。



It works nice. It shows up in the results window in the familiar tabular format.


这篇关于如何通过SQL获取本地驱动器上的文本文件的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆