当前位置:网站首页>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\
边栏推荐
- 手机股票开户安全吗?靠不靠谱啊?
- Go language learning tutorial (16)
- Fundamentals of deep learning convolutional neural network (CNN)
- 众昂矿业:2022年全球萤石行业市场供给现状分析
- Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
- BZOJ 3747 POI2015 Kinoman 段树
- 【无标题】
- leetcode刷题:二叉树14(左叶子之和)
- Postman core function analysis - parameterization and test report
- Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
猜你喜欢
What do software test engineers do? How about the prospect of treatment?
淺淺的談一下ThreadLocalInsecureRandom
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
How about testing outsourcing companies?
leetcode刷题:二叉树10(完全二叉树的节点个数)
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
深度学习 卷积神经网络(CNN)基础
再忙不能忘安全
随机推荐
Go language | 01 wsl+vscode environment construction pit avoidance Guide
ffplay文档[通俗易懂]
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
leetcode刷题:二叉树12(二叉树的所有路径)
浅浅的谈一下ThreadLocalInsecureRandom
Flume series: interceptor filtering data
Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
C - sequential structure
No matter how busy you are, you can't forget safety
How to select the Block Editor? Impression notes verse, notation, flowus
Information / data
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL
JVMRandom不可设置种子|问题追溯|源码追溯
2023年深圳市绿色低碳产业扶持计划申报指南
Interviewer: what is the internal implementation of set data types in redis?
司空见惯 - 英雄扫雷鼠
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
Cocos2d-x项目总结中的一些遇到的问题
UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
C application interface development foundation - form control (5) - grouping control