当前位置:网站首页>Process file and directory names
Process file and directory names
2022-07-05 19:56:00 【User 7741497】
%Library.File
Class provides several class methods that can be used to handle file names and directory names . in the majority of cases , Files and directories do not need to exist to use these methods .
Get file name and directory name
%Library.File
Class provides class methods that can be used to get some file names and directory names .
Given the full pathname , Use GetDirectory()
and GetFilename()
Get the directory and short file name respectively . For this method , Partial directory names are not allowed .
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
Given the file name , Use CanonicalFilename()
Get the full path from the root directory :
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")
If the file cannot be opened ,CanonicalFilename()
Method will return an empty string .
Give a directory name , Use ComputeFullDBDir()
Construct the canonical form of the directory name .
DHC-APP>write ##class(%File).ComputeFullDBDir("foodirectory")
C:\InterSystems\Cache\mgr\foodirectory\
Given the directory name , Use GetDirectoryLength()
and GetDirectoryPiess()
Get the number of fragments in the directory and the number of fragments of a specific fragment . Fragments can be slashed (/
) Or backslash (\
) Separate , It depends on the operating system .
DHC-APP>set dir = "e:\temp"
DHC-APP>write ##class(%File).GetDirectoryLength(dir)
2
DHC-APP>write ##class(%File).GetDirectoryPiece(dir,1)
E:
Given the file name or directory name , Use ParentDirectoryName()
Get parent directory .
DHC-APP>set dir = "stream"
DHC-APP>write ##class(%File).ParentDirectoryName(dir)
E:\DtHealth\db\dthis\data\
Normalize file names and directory names
%Library.File
Class provides class methods that return normalized file names and directory names ( Follow the naming rules of the operating system running the server ). When you create a new file name and directory name by appending a name fragment to an existing name , These options are very useful .
Given a file name ,NormalizeFilename()
Return the normalized file name .
Given directory name ,NormalizeDirectory()
Return the normalized directory name .
These methods return normalized names suitable for use on the underlying operating system , And will try to standardize slashes (/
) Or backslash (\
) Path separator .
Windows Example :
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.txt
UNIX Example :
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/
When one of these methods is called to normalize the directory name or file name relative to the specified directory , Please add the second parameter . The directory must exist .
Windows Example :
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 Example :
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()
The method is similar to NormalizeDirectory()
Two parameter form of , But the order of the parameters is the opposite . Besides , The directory does not need to exist . Pass... In the third argument 1 To add the trailing separator , Or pass it on 0 To omit it ( The default value is ).
Windows Example :
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 Example :
USER>write ##class(%File).SubDirectoryName("/foobar", "samples")
/foobar/samples
USER>write ##class(%File).SubDirectoryName("", "stream", 1)
/InterSystems/IRIS/mgr/user/stream/
Handle file and directory names with spaces
For file names and directory names that contain spaces , Please use NormalizeFilenameWithSpaces()
, It will handle the spaces in the path name according to the host platform . And normalized file names () And standardized catalogue () Different , This method accepts only one parameter , You cannot normalize a file or directory name relative to another directory , You cannot normalize some file or directory names relative to the default directory .
stay Windows On the system , If the pathname contains spaces , And the file or directory does not exist , Then the method returns the pathname enclosed in double quotation marks . If the pathname contains spaces , And the file or directory does exist , Then the method returns the short form of the pathname . If the pathname does not contain spaces , This method will return the pathname intact .
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
stay Unix On the system , If the pathname contains spaces , This method will return the pathname enclosed in double quotation marks . If the pathname does not contain spaces , This method will return the pathname intact .
USER>write ##class(%File).NormalizeFilenameWithSpaces("/InterSystems/my directory")
"/InterSystems/my directory"
USER>write ##class(%File).NormalizeFilenameWithSpaces("iris.dat")
iris.dat
Build and deconstruct file and directory names
%Library.File
Class provides class methods that allow you to construct file names from path arrays , Or deconstruct the file name into a path array .
Given an array of paths ,Construct()
Assemble the path and return the file name . The constructed file name is suitable for the server platform . Calling this method without parameters will return the default directory .
Given a file name ,Deconstruct()
Decompose the file name and return an array of paths . The content of the array is suitable for the server platform .
Below Windows The example passes the array directory to Construction()
. The empty string in the last array position indicates that the returned file name should be in a \
ending .
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\
Below Unix Example called without parameters Construction()
. This method returns the default directory .
USER>set default = ##class(%File).Construct()
USER>write default
/InterSystems/IRIS/mgr/user
Below Unix Example call Deconstruct()
, It gets variables default And store them in an array defaultdir
in .
USER>do ##class(%File).Deconstruct(default, .defaultdir)
USER>zwrite defaultdir
defaultdir=4
defaultdir(1)="InterSystems"
defaultdir(2)="IRIS"
defaultdir(3)="mgr"
defaultdir(4)="user"
obtain System Manager Catalog
Use ManagerDirectory()
Method to get installdir/mgr
The fully qualified name of the directory . for example :
DHC-APP>write ##class(%File).ManagerDirectory()
C:\InterSystems\Cache\mgr\
边栏推荐
- id选择器和类选择器的区别
- SecureRandom那些事|真伪随机数
- 【硬核干货】数据分析哪家强?选Pandas还是选SQL
- What are general items
- 城链科技数字化创新战略峰会圆满召开
- 【无标题】
- 2023年深圳市绿色低碳产业扶持计划申报指南
- [Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
- leetcode刷题:二叉树14(左叶子之和)
- Fundamentals of shell programming (Chapter 9: loop)
猜你喜欢
leetcode刷题:二叉树13(相同的树)
通过POI追加数据到excel中小案例
安卓面试宝典,2022Android面试笔试总结
40000 word Wenshuo operator new & operator delete
Elk distributed log analysis system deployment (Huawei cloud)
【硬核干货】数据分析哪家强?选Pandas还是选SQL
How to apply smart contracts more wisely in 2022?
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
leetcode刷题:二叉树10(完全二叉树的节点个数)
随机推荐
Webuploader file upload drag upload progress monitoring type control upload result monitoring control
司空见惯 - 英雄扫雷鼠
成功入职百度月薪35K,2022Android开发面试解答
No matter how busy you are, you can't forget safety
[untitled]
C#应用程序界面开发基础——窗体控制(5)——分组类控件
完爆面试官,一线互联网企业高级Android工程师面试题大全
C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
再忙不能忘安全
acm入门day1
Is the education of caiqiantang reliable and safe?
【c语言】快速排序的三种实现以及优化细节
【硬核干货】数据分析哪家强?选Pandas还是选SQL
力扣 1200. 最小绝对差
浅浅的谈一下ThreadLocalInsecureRandom
挖财钱堂教育靠谱安全吗?
深度学习 卷积神经网络(CNN)基础
力扣 729. 我的日程安排表 I
UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
Securerandom things | true and false random numbers