当前位置:网站首页>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.txtUNIX 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.datstay 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.datBuild 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\边栏推荐
- 【obs】libobs-winrt :CreateDispatcherQueueController
- Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
- [OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
- c语言oj得pe,ACM入门之OJ~
- 40000 word Wenshuo operator new & operator delete
- What is the core value of testing?
- acm入门day1
- CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
- 【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
- Securerandom things | true and false random numbers
猜你喜欢

leetcode刷题:二叉树18(最大二叉树)

Database logic processing function

Redis cluster simulated message queue

通过POI追加数据到excel中小案例
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
![[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*

如何安全快速地从 Centos迁移到openEuler

司空见惯 - 英雄扫雷鼠

SecureRandom那些事|真伪随机数

What does software testing do? What are the requirements for learning?
随机推荐
What do software test engineers do? How about the prospect of treatment?
Add data to excel small and medium-sized cases through poi
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
完爆面试官,一线互联网企业高级Android工程师面试题大全
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
That's awesome. It's enough to read this article
No matter how busy you are, you can't forget safety
Summer Challenge harmonyos - realize message notification function
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
处理文件和目录名
Go language learning tutorial (XV)
Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
Build your own website (16)
leetcode刷题:二叉树16(路径总和)
How to select the Block Editor? Impression notes verse, notation, flowus
openh264解码数据流向分析
Debezium series: parsing the default value character set
安卓面试宝典,2022Android面试笔试总结
Go language | 01 wsl+vscode environment construction pit avoidance Guide