当前位置:网站首页>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
边栏推荐
- 一朵云开启智慧交通新未来
- Icml2022 | partial and asymmetric comparative learning of out of distribution detection in long tail recognition
- Is it complicated to open an account? Is online account opening safe?
- Is it safe to make fund fixed investment on access letter?
- 项目中遇到的问题 u-parse 组件渲染问题
- Pytorch yolov5 training custom data
- 瞅一瞅JUC提供的限流工具Semaphore
- Cronab log: how to record the output of my cron script
- Rse2020/ cloud detection: accurate cloud detection of high-resolution remote sensing images based on weak supervision and deep learning
- Is it safe to open an account, register and dig money? Is there any risk? Is it reliable?
猜你喜欢
FCN: Fully Convolutional Networks for Semantic Segmentation
U-Net: Convolutional Networks for Biomedical Images Segmentation
Take a look at semaphore, the current limiting tool provided by JUC
Thoroughly understand why network i/o is blocked?
The era of Web3.0 is coming. See how Tianyi cloud storage resources revitalize the system to enable new infrastructure (Part 2)
一朵云开启智慧交通新未来
LeetCode 6111. 螺旋矩阵 IV
The 11th China cloud computing standards and Applications Conference | China cloud data has become the deputy leader unit of the cloud migration special group of the cloud computing standards working
How to write good code defensive programming
Ant group open source trusted privacy computing framework "argot": open and universal
随机推荐
2022 latest intermediate and advanced Android interview questions, [principle + practice + Video + source code]
[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
Icml2022 | partial and asymmetric comparative learning of out of distribution detection in long tail recognition
Pytorch yolov5 training custom data
[detailed explanation of AUTOSAR 14 startup process]
5. Data access - entityframework integration
7-1 链表也简单fina
Summary of six points of MySQL optimization
Solutions contents have differences only in line separators
The main thread anr exception is caused by too many binder development threads
Mysql database indexing tutorial (super detailed)
SAP feature description
What are the cache interfaces of nailing open platform applet API?
音视频包的pts,dts,duration的由来.
开户注册挖财安全吗?有没有风险的?靠谱吗?
max31865模块RTD测温注意事项
AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务
Use QT to traverse JSON documents and search sub objects
@Extension, @spi annotation principle
Use JMeter to record scripts and debug