当前位置:网站首页>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\
边栏推荐
- Android interview classic, 2022 Android interview written examination summary
- 线程池参数及合理设置
- 完爆面试官,一线互联网企业高级Android工程师面试题大全
- webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
- acm入门day1
- leetcode刷题:二叉树12(二叉树的所有路径)
- Redis cluster simulated message queue
- 40000 word Wenshuo operator new & operator delete
- ffplay文档[通俗易懂]
- Reptile exercises (II)
猜你喜欢
leetcode刷题:二叉树15(找树左下角的值)
深度学习 卷积神经网络(CNN)基础
95后阿里P7晒出工资单:狠补了这个,真香...
Based on vs2017 and cmake GUI configuration, zxing and opencv are used in win10 x64 environment, and simple detection of data matrix code is realized
Force buckle 1200 Minimum absolute difference
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
leetcode刷题:二叉树12(二叉树的所有路径)
Interviewer: what is the internal implementation of set data types in redis?
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
Add data to excel small and medium-sized cases through poi
随机推荐
What do software test engineers do? How about the prospect of treatment?
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
leetcode刷题:二叉树12(二叉树的所有路径)
Force buckle 1200 Minimum absolute difference
深度学习 卷积神经网络(CNN)基础
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
okcc呼叫中心有什么作用
Concept and syntax of function
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Summer Challenge harmonyos - realize message notification function
使用 RepositoryProvider简化父子组件的传值
【obs】libobs-winrt :CreateDispatcherQueueController
That's awesome. It's enough to read this article
S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
再忙不能忘安全
期货如何网上开户?安不安全?
C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
Flume series: interceptor filtering data
Is it safe to open a mobile stock account? Is it reliable?
Cocos2d-x项目总结中的一些遇到的问题