当前位置:网站首页>处理文件和目录名
处理文件和目录名
2022-07-05 19:53:00 【用户7741497】
%Library.File类提供了几个可用于处理文件名和目录名的类方法。在大多数情况下,文件和目录不需要存在即可使用这些方法。
获取文件名和目录名
%Library.File类提供可用于获取部分文件名和目录名的类方法。
在给定完整路径名的情况下,使用GetDirectory()和GetFilename()分别获取目录和短文件名。对于此方法,不允许使用部分目录名。
DHC-APP>set filename = "e:\temp\config.txt"
DHC-APP>write ##class(%File).GetDirectory(filename)
E:\temp\
DHC-APP>write ##class(%File).GetFilename(filename)
config.txt在给定文件名的情况下,使用CanonicalFilename()从根目录获取完整路径:
DHC-APP>set filename = "cache.dat"
DHC-APP>write ##class(%File).CanonicalFilename(filename)
e:\dthealth\db\dthis\data\cache.dat
DHC-APP>write ##class(%File).CanonicalFilename("foo.dat")如果文件无法打开,CanonicalFilename()方法将返回空字符串。
给定一个目录名,使用ComputeFullDBDir()构造目录名的规范形式。
DHC-APP>write ##class(%File).ComputeFullDBDir("foodirectory")
C:\InterSystems\Cache\mgr\foodirectory\在给定目录名的情况下,使用GetDirectoryLength()和GetDirectoryPiess()分别获取目录中的片断数和特定片断的片断数。片断可以用斜杠(/)或反斜杠(\)分隔,具体取决于操作系统。
DHC-APP>set dir = "e:\temp"
DHC-APP>write ##class(%File).GetDirectoryLength(dir)
2
DHC-APP>write ##class(%File).GetDirectoryPiece(dir,1)
E:在给定文件名或目录名的情况下,使用ParentDirectoryName()获取父目录。
DHC-APP>set dir = "stream"
DHC-APP>write ##class(%File).ParentDirectoryName(dir)
E:\DtHealth\db\dthis\data\规范化文件名和目录名
%Library.File类提供返回规范化文件名和目录名的类方法(遵循运行服务器的操作系统的命名规则)。当通过将名称片段附加到现有名称来创建新的文件名和目录名时,这些选项非常有用。
给定一个文件名,NormalizeFilename()返回规范化的文件名.
给定目录名,NormalizeDirectory()返回规范化的目录名。
这些方法返回适合在底层操作系统上使用的规范化名称,并将尝试标准化斜杠(/)或反斜杠(\)路径分隔符。
Windows示例:
DHC-APP>write ##class(%File).NormalizeDirectory("stream")
E:\DtHealth\db\dthis\data\stream\
DHC-APP>write ##class(%File).NormalizeFilename("c:\temp//config.txt")
C:\temp\config.txtUNIX示例:
USER>set filename = "/tmp//samples/myfile.txt"
USER>write ##class(%File).NormalizeFilename(filename)
/tmp/samples/myfile.txt
USER>write ##class(%File).NormalizeDirectory("stream")
/InterSystems/IRIS/mgr/user/stream/在调用这些方法之一以规范化相对于指定目录的目录名或文件名时,请添加第二个参数。该目录必须存在。
Windows示例:
DHC-APP>write ##class(%File).NormalizeFilename("config.txt", "e:\temp")
E:\temp\config.txt
DHC-APP>write ##class(%File).NormalizeDirectory("stream", "")
E:\DtHealth\db\dthis\data\stream\Unix示例:
USER>write ##class(%File).NormalizeFilename("myfile.txt", "/tmp/samples")
/tmp/samples/myfile.txt
USER>write ##class(%File).NormalizeDirectory("stream", "")
/InterSystems/IRIS/mgr/user/stream/SubDirectoryName()方法类似于NormalizeDirectory()的双参数形式,只是参数的顺序相反。此外,该目录不需要存在。在第三个参数中传递1以添加尾部分隔符,或者传递0以省略它(默认值)。
Windows示例:
DHC-APP>write ##class(%File).SubDirectoryName("C:\foobar", "samples")
C:\foobar\samples
DHC-APP>write ##class(%File).SubDirectoryName("", "stream", 1)
E:\DtHealth\db\dthis\data\stream\Unix示例:
USER>write ##class(%File).SubDirectoryName("/foobar", "samples")
/foobar/samples
USER>write ##class(%File).SubDirectoryName("", "stream", 1)
/InterSystems/IRIS/mgr/user/stream/用空格处理文件和目录名
对于包含空格的文件名和目录名,请使用NormalizeFilenameWithSpaces(),它会根据主机平台处理路径名中的空格。与规格化文件名()和规格化目录()不同,此方法只接受一个参数,不能相对于另一个目录规格化文件或目录名,也不能相对于默认目录规格化部分文件或目录名。
在Windows系统上,如果路径名包含空格,并且文件或目录不存在,则该方法返回用双引号括起来的路径名。如果路径名包含空格,并且文件或目录确实存在,则该方法返回路径名的简短形式。如果路径名不包含空格,该方法将原封不动地返回路径名。
DHC-APP>write ##class(%File).NormalizeFilenameWithSpaces("C:\temp\nonexistant folder") "C:\temp\nonexistant folder"
DHC-APP>write ##class(%File).NormalizeFilenameWithSpaces("C:\temp\existant folder") "C:\temp\existant folder"
DHC-APP>write ##class(%File).NormalizeFilenameWithSpaces("iris.dat")
iris.dat
DHC-APP>write ##class(%File).NormalizeFilenameWithSpaces("cache.dat")
cache.dat在Unix系统上,如果路径名包含空格,该方法将返回用双引号括起来的路径名。如果路径名不包含空格,该方法将原封不动地返回路径名。
USER>write ##class(%File).NormalizeFilenameWithSpaces("/InterSystems/my directory")
"/InterSystems/my directory"
USER>write ##class(%File).NormalizeFilenameWithSpaces("iris.dat")
iris.dat构建和解构文件和目录名
%Library.File类提供的类方法允许从路径数组构造文件名,或将文件名解构为路径数组。
给定一个路径数组,Construct()组装路径并返回文件名。构造的文件名适合服务器平台。在没有参数的情况下调用此方法会返回默认目录。
给定一个文件名,Deconstruct()分解文件名并返回一个路径数组。阵列的内容适合服务器平台。
下面的Windows示例将数组目录传递给Construction()。最后一个数组位置中的空字符串表示返回的文件名应以a \结尾。
USER>zwrite dirs
dirs=4
dirs(1)="C:"
dirs(2)="Temp"
dirs(3)="samples"
dirs(4)=""
USER>write ##class(%File).Construct(dirs...)
C:\Temp\samples\下面的Unix示例在不带参数的情况下调用Construction()。该方法返回默认目录。
USER>set default = ##class(%File).Construct()
USER>write default
/InterSystems/IRIS/mgr/user下面的Unix示例调用Deconstruct(),它获取变量default中的路径并将它们存储在数组defaultdir中。
USER>do ##class(%File).Deconstruct(default, .defaultdir)
USER>zwrite defaultdir
defaultdir=4
defaultdir(1)="InterSystems"
defaultdir(2)="IRIS"
defaultdir(3)="mgr"
defaultdir(4)="user"获取System Manager目录
使用ManagerDirectory()方法获取installdir/mgr目录的完全限定名称。例如:
DHC-APP>write ##class(%File).ManagerDirectory()
C:\InterSystems\Cache\mgr\边栏推荐
- Add data to excel small and medium-sized cases through poi
- UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
- 力扣 729. 我的日程安排表 I
- Force buckle 1200 Minimum absolute difference
- gst-launch的-v参数
- How to apply smart contracts more wisely in 2022?
- C application interface development foundation - form control (5) - grouping control
- acm入门day1
- leetcode刷题:二叉树15(找树左下角的值)
- openh264解码数据流向分析
猜你喜欢
![[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*](/img/cc/172684664a9115943d45b0646ef110.png)
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*

Xaas trap: all things serve (possible) is not what it really needs

Securerandom things | true and false random numbers

Base du réseau neuronal de convolution d'apprentissage profond (CNN)

如何安全快速地从 Centos迁移到openEuler
完爆面试官,一线互联网企业高级Android工程师面试题大全

Fundamentals of deep learning convolutional neural network (CNN)

力扣 729. 我的日程安排表 I

95后阿里P7晒出工资单:狠补了这个,真香...

Using repositoryprovider to simplify the value passing of parent-child components
随机推荐
四万字长文说operator new & operator delete
95后阿里P7晒出工资单:狠补了这个,真香...
Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
Float. The specific meaning of the return value of floattorawintbits is to convert float into byte array
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
安卓面试宝典,2022Android面试笔试总结
Android interview classic, 2022 Android interview written examination summary
aggregate
Debezium series: PostgreSQL loads the correct last submission LSN from the offset
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
Securerandom things | true and false random numbers
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
Force buckle 1200 Minimum absolute difference
c——顺序结构
《乔布斯传》英文原著重点词汇笔记(十二)【 chapter ten & eleven】
通配符选择器
Analysis of openh264 decoded data flow
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
司空见惯 - 英雄扫雷鼠