当前位置:网站首页>Use file and directory properties and properties
Use file and directory properties and properties
2022-07-05 18:47:00 【User 7741497】
Use file and directory properties and properties
%Library.File
Class also provides many class methods , You can use these methods to get information about files and directories , Or view or set their properties and properties .
Check whether the files and directories exist
To determine whether a given file exists , Please use Existes()
Method and specify the file name as the parameter . for example :
DHC-APP>write ##class(%File).Exists("e:\temp\")
1
Again , To find out whether a given directory exists , Please use DirectoryExists()
Method , And specify the directory as the parameter . for example :
DHC-APP>write ##class(%File).DirectoryExists("e:\temp")
1
As mentioned earlier , These methods are in Unix
Treat file or directory names as case sensitive , But in Windows Upper case insensitive . Besides , If you specify part of the file name or directory name , Then the file or directory referenced by this method is relative to the directory of the default global database containing the namespace being used . for example :
DHC-APP>write ##class(%File).Exists("cache.dat")
1
View and set file and directory permissions
%Library.File
Class provides many class methods , You can use these methods to view or set the permissions of files or directories .
Check whether the file or directory is read-only or writable
Given the file or directory name , If the file or directory is read-only ,ReadOnly()
Method returns 1, Otherwise return to 0:
DHC-APP>write ##class(%File).ReadOnly("export.xml")
1
DHC-APP>write ##class(%File).ReadOnly("E:\temp")
0
Again , Given a file or directory name , If the file or directory can be written , be Writeable()
Method returns 1, Otherwise return to 0:
DHC-APP>write ##class(%File).Writeable("export.xml")
0
DHC-APP>write ##class(%File).Writeable("e:\temp")
1
Make the file or directory read-only or writable ( window )
To make Windows Files or directories on become read-only , Please use SetReadOnly()
Method , This method returns a Boolean value indicating success or failure . This method takes three parameters , The second parameter is in Windows Is omitted from . The first parameter is the name of the file or directory . The third parameter is the output parameter . If a negative , It contains the error code returned by the operating system , In case the method fails .
In the following example , Yes SetReadOnly()
The call to successfully put the file "e:\temp\config.txt
Change to read-only .
DHC-APP>write ##class(%File).ReadOnly("e:\temp\config.txt")
0
DHC-APP>write ##class(%File).SetReadOnly("e:\temp\config.txt",,.return)
1
DHC-APP>write ##class(%File).ReadOnly("e:\temp\config.txt")
In the following example , Yes SetReadOnly()
Call of failed ,Windows The system error code is 5, It means “ Access denied .”
DHC-APP>write ##class(%File).SetReadOnly("C:\",,.return)
0
DHC-APP>w return
-5
To make Windows Files or directories on can be written , Please use SetWriteable()
Method . This method uses the same three parameters , The second parameter is in Windows Is omitted again .
DHC-APP>write ##class(%File).Writeable("e:\temp\config.txt")
0
DHC-APP>write ##class(%File).SetWriteable("e:\temp\config.txt",,.return)
1
DHC-APP>write ##class(%File).Writeable("e:\temp\config.txt")
1
Make the file or directory read-only or writable (Unix)
stay Unix On , You can also use SetReadOnly()
and SetWriteable()
Method , But due to the existence of the second parameter , Their behavior is somewhat different .
however , stay Unix in , For the owner 、 Groups and users specify different permissions . To better control file and directory permissions , See the section viewing or setting file and directory properties .
View and set file and directory properties
To view or set the properties of a file or directory at a more detailed level , Please use %Library.File
Of Attributes()
and SetAttributes()
Method . File attributes are represented by a sequence of bits collectively expressed as integers . The meaning of each bit depends on the underlying operating system .
View file and directory properties
%Library.File
Of Attributes()
Method requires a file name or directory name as a parameter , And return the attribute bit sequence represented by an integer .
The following example is in Windows Running on the system :
DHC-APP>write ##class(%File).Attributes("cache.dat")
32
DHC-APP>write ##class(%File).Attributes("e:\temp")
16
DHC-APP>write ##class(%File).Attributes("secret.zip")
35
DHC-APP>write ##class(%File).Attributes("e:\temp\config.txt")
32
In the first example ,32
Express cache.dat
It's an archive file . In the second example ,16
Express C:\temp
Is a directory . In the third example , More than one bit is set ,35
Express secret.zip
It's hidden (2) And read only (1) The archive (32). Add 32 + 2 + 1 = 35
.
The following example is in Unix Running on the system :
write ##class(%File).Attributes("/home")
16877
In this case ,16877
Express /home
Is a directory (16384), The owner owns the read (256)、 write in (128) And execution (64) jurisdiction ; Read (32) And execution (8) Group permission ; And read for others (4) And execution (1) jurisdiction . add 16384+256+128+64+32+8+4+1 = 16877
.
Set file and directory properties
contrary ,SetAttributes()
Method to set the properties of a file or directory , And return a Boolean value to indicate success or failure . This method requires three parameters . The first parameter is the name of the file or directory . The second parameter is an integer , Indicates that the file or directory has the required attributes . The third parameter is the output parameter . If a negative , It contains the error code returned by the operating system , In case the method fails .
The following example is in Windows On , By setting 1 position , Make the document e:\temp\config.txt
Become a read-only file :
DHC-APP>write ##class(%File).Attributes("e:\temp\config.txt")
32
DHC-APP>write ##class(%File).SetAttributes("e:\temp\config.txt",33,.return)
1
DHC-APP>write ##class(%File).Attributes("e:\temp\config.txt")
33
The following example is in Unix On , Set the files in the default directory myfile
From 644 Change to full permission (777):
USER>write ##class(%File).Attributes("myfile")
33188
USER>write ##class(%File).SetAttributes("myfile",33279,.return)
1
USER>write ##class(%File).Attributes("myfile")
33279
By placing the regular file (32768) Value of and owner (448)、 Group (56) And others (7) Add the masks of to calculate the expected attribute value .
View other file and directory properties
%Library.File
Other class methods of allow you to check various other properties of files and directories .
GetFileDateCreated()
Method returns with $H Format the date the file or directory was created :
DHC-APP>write $zdate(##class(%File).GetFileDateCreated("stream"))
04/11/2020
DHC-APP>write $zdate(##class(%File).GetFileDateCreated("e:\temp"))
03/27/2021
Be careful :Windows It is currently the only platform to track the actual creation date . Other platforms store the date of the last file state change .
GetFileDateModified()
Methods to $H Format returns the modified date of the file or directory :
DHC-APP>write $zdate(##class(%File).GetFileDateModified("cache.dat"))
07/11/2021
Method returns the size of the file , In bytes :
DHC-APP>write ##class(%File).GetFileSize("e:\temp\config.txt")
220
GetDirectorySpace()
Method returns the amount of free space and total space in the drive or directory . According to the fourth parameter ( It can be 0、1 or 2) Value , Space can be in bytes 、MB( The default value is ) or GB Return... For units . In this case ,2 Represent space with GB Return... For units :
DHC-APP>set status = ##class(%File).GetDirectorySpace("C:", .FreeSpace, .TotalSpace, 2)
DHC-APP>write FreeSpace
128.83
DHC-APP>write TotalSpace
247.97
stay Windows On , If you pass the directory name to this method , The amount of space returned is the amount of space on the entire drive .
about GetDirectorySpace()
Method , Any error status returned is an operating system level error . In the following example ,Windows System error code 3 Express “ The system could not find the specified path .”
DHC-APP>set status = ##class(%File).GetDirectorySpace("Q:", .FreeSpace, .TotalSpace, 2)
DHC-APP>do $system.Status.DisplayError(status)
error #83: Error code =3
边栏推荐
- Ant group open source trusted privacy computing framework "argot": open and universal
- Low code practice of xtransfer, a cross-border payment platform: how to integrate with other medium-sized platforms is the core
- 案例分享|金融业数据运营运维一体化建设
- The easycvr authorization expiration page cannot be logged in. How to solve it?
- Is it safe for golden sun to open an account? Can I open an account free of 5 in case?
- Insufficient picture data? I made a free image enhancement software
- Is it safe for Apple mobile phone to speculate in stocks? Is it a fraud to get new debts?
- Oracle日期格式转换 to_date,to_char,to_timetamp 相互转换
- 图扑软件数字孪生智慧风电系统
- Lombok @builder annotation
猜你喜欢
鱼和熊掌可以兼得!天翼云弹性裸金属一招鲜!
小程序 修改样式 ( placeholder、checkbox的样式)
How to automatically install pythn third-party libraries
The main thread anr exception is caused by too many binder development threads
技术分享 | 接口测试价值与体系
Web3.0时代来了,看天翼云存储资源盘活系统如何赋能新基建(下)
The era of Web3.0 is coming. See how Tianyi cloud storage resources revitalize the system to enable new infrastructure (Part 2)
AI金榜题名时,MLPerf榜单的份量究竟有多重?
爬虫01-爬虫基本原理讲解
MySQL优化六个点的总结
随机推荐
[HCIA cloud] [1] definition of cloud computing, what is cloud computing, architecture and technical description of cloud computing, Huawei cloud computing products, and description of Huawei memory DD
Problems encountered in the project u-parse component rendering problems
U-Net: Convolutional Networks for Biomedical Images Segmentation
Common time complexity
Video fusion cloud platform easycvr adds multi-level grouping, which can flexibly manage access devices
线性表——抽象数据类型
LeetCode 6109. Number of people who know the secret
AI open2022 | overview of recommendation systems based on heterogeneous information networks: concepts, methods, applications and resources
What are the cache interfaces of nailing open platform applet API?
爬虫01-爬虫基本原理讲解
5. Data access - entityframework integration
技术分享 | 接口测试价值与体系
About statistical power
Reading notes of Clickhouse principle analysis and Application Practice (5)
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
AI Open2022|基于异质信息网络的推荐系统综述:概念,方法,应用与资源
Overview of video self supervised learning
跨境支付平台 XTransfer 的低代码实践:如何与其他中台融合是核心
Lombok @builder annotation
MYSQL中 find_in_set() 函数用法详解