当前位置:网站首页>【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
2022-07-06 17:01:00 【dssgresadfsrgre】
一、查看或修改文件属性——ATTRIB
先执行命令【attrib /?】,看看帮助信息。
C:\Users\Administrator>attrib /?
显示或更改文件属性。
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [+O | -O] [+I | -I] [+X | -X] [+P | -P] [+U | -U]
[drive:][path][filename] [/S [/D]] [/L]
+ 设置属性。
- 清除属性。
R 只读文件属性。
A 存档文件属性。
S 系统文件属性。
H 隐藏文件属性。
O 脱机属性。
I 无内容索引文件属性。
X 无清理文件属性。
V 完整性属性。
P 固定属性。
U 非固定属性。
[drive:][path][filename]
指定属性要处理的文件。
/S 处理当前文件夹及其所有子文件夹中
的匹配文件。
/D 也处理文件夹。
/L 处理符号链接和
符号链接目标的属性
C:\Users\Administrator>例:
md autorun
attrib +a +s +h autorun上面的命令将建立文件夹autorun,然后将其设为存档、系统、隐藏属性
二、查看与修改文件扩展名关联的文件类型——assoc
2.1 显示命令assoc的帮助信息
打印assoc的帮助信息,执行命令【assoc /?】。
C:\Users\Administrator>assoc /?
显示或修改文件扩展名关联
ASSOC [.ext[=[fileType]]]
.ext 指定跟文件类型关联的文件扩展名
fileType 指定跟文件扩展名关联的文件类型
键入 ASSOC 而不带参数,显示当前文件关联。如果只用文件扩展
名调用 ASSOC,则显示那个文件扩展名的当前文件关联。如果不为
文件类型指定任何参数,命令会删除文件扩展名的关联。
C:\Users\Administrator>2.2 显示所有扩展名对应的文件类型
执行不带任何参数的命令【assoc】,得到所有扩展名对应的文件类型,如下所示(仅摘录一部分)。
C:\Users\Administrator>assoc
.3ds=Photoshop.3DSFileType.140
.3gp=WMP11.AssocFile.3GP
.AAC=WMP11.AssocFile.ADTS
.abr=Photoshop.BrushesFile
.csv=Excel.CSV
.dat=xmp.dat
.db=ANSYS 2020 R2 .db File
.doc=Word.Document.8
.dll=dllfile
.mp3=WMP11.AssocFile.MP3
.mp4=WMP11.AssocFile.MP4
.mpeg=WMP11.AssocFile.MPEG
.png=pngfile
.txt=txtfile
.xml=xmlfile2.3 显示指定文件扩展名对应的文件类型
执行带有扩展名参数的命令【assoc .ext】,会显示扩展名对应的文件类型。
例如执行【assoc .exe】,返回结果是【.exe=exefile】,说明.exe对应的文件类型是exefile。
另外.txt的文件类型是txtfile,而.doc的文件类型是Word.Document.8。
assoc .txt #显示.txt代表的'文件类型',结果显示 .txt=txtfile
assoc .doc #显示.doc代表的'文件类型',结果显示 .doc=Word.Document.8
三、查看与修改文件扩展名关联的程序——ftype
3.1 查看命令ftype的帮助信息
先执行命令【ftype /?】,查看帮助信息。
C:\Users\Administrator>ftype /?
显示或修改用在文件扩展名关联中的文件类型
FTYPE [fileType[=[openCommandString]]]
fileType 指定要检查或改变的文件类型
openCommandString 指定调用这类文件时要使用的开放式命令。
键入 FTYPE 而不带参数来显示当前有定义的开放式命令字符串的
文件类型。FTYPE 仅用一个文件类型启用时,它显示那个文件类
型目前的开放式命令字符串。如果不为开放式命令字符串指定,
FTYPE 命令将删除那个文件类型的开放式命令字符串。在一个
开放式命令字符串之内,命令字符串 %0 或 %1 被通过关联调用
的文件名所代替。%* 得到所有的参数,%2 得到第一个参数,
%3 得到第二个,等等。%~n 得到其余所有以 nth 参数打头的
参数;n 可以是从 2 到 9 的数字。例如:
ASSOC .pl=PerlScript
FTYPE PerlScript=perl.exe %1 %*
允许你启用以下 Perl 脚本:
script.pl 1 2 3
如果不想键入扩展名,则键入以下字符串:
set PATHEXT=.pl;%PATHEXT%
被启动的脚本如下:
script 1 2 3
C:\Users\Administrator>3.2 查看所有文件类型对应的启动程序
执行不带参数的ftype命令,结果如下(不完全)。
C:\Users\Administrator>ftype
Excel.CSV="D:\Program Files\Microsoft Office\Office16\EXCEL.EXE" /dde
Folder=%SystemRoot%\Explorer.exe
http="C:\Program Files\Internet Explorer\iexplore.exe" %1
https="C:\Program Files\Internet Explorer\iexplore.exe" %1
kugou="D:\Program Files (x86)\KuGou\KGMusic\KuGou.exe" "%1"
Python.ArchiveFile="C:\WINDOWS\py.exe" "%L" %*
Python.CompiledFile="C:\WINDOWS\py.exe" "%L" %*
Python.File="C:\WINDOWS\py.exe" "%L" %*
Python.NoConArchiveFile="C:\WINDOWS\pyw.exe" "%L" %*
Python.NoConFile="C:\WINDOWS\pyw.exe" "%L" %*
WinRAR="D:\Program Files\WinRAR\WinRAR.exe" "%1"
WinRAR.REV="D:\Program Files\WinRAR\WinRAR.exe" "%1"
WinRAR.ZIP="D:\Program Files\WinRAR\WinRAR.exe" "%1"3.3 查看指定文件类型对应的启动程序
语法规则。
ftype filetype # 文件类型字符串前不用添加点号执行命令【ftype exefile】,结果为【exefile="%1" %*】。
执行命令【ftype txtfile】,结果为【txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1】。
3.4 修改指定文件类型对应的启动程序
语法规则。
ftype filetype=openCommandString # 文件类型字符串前不用添加点号普通用户一般用不上这种规则,因为启动程序字符串太难懂。
对于一般用户来说,经常用到的操作无非就是将某一个扩展名和某一文件类型关联起来,比如doc与word应用关联,这是不需要用到ftype命令的,直接用一个命令【assoc .doc=Word.Document.8】即可。
三、windows系统打开文件的流程
当你双击一个.txt文件时,windows并不是根据.txt直接判断用 notepad.exe 打开。
而是先由命令【assoc .txt】的执行结果【.txt=txtfile】判断得知.txt属于txtfile文件类型,
再调用txtfile关联的命令行,也即【txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1】所对应的程序。
四、windows恢复文件关联
4.1 除了exe程序,恢复关联直接用命令
例如,上面执行命令【assoc .txt=Word.Document.8】,对txt扩展名文件更改文件类型后,要想恢复至原先的关联,可以用命令【assoc .txt=txtfile】
4.2 对于exe程序,恢复关联需要用到.com
exe文件是windows系统中的可执行文件,而文件关联决定了文件的打开方式。
当我们不小心更改exe程序关联后,cmd程序无法正常打开。
如何正确恢复exe文件关联呢?
首先在C:\WINDOWS\system32(64位WOW64)目录下找到cmd.exe,选中文件后按下F2键,修改文件名为cmd.com。
接着双击执行cmd.com,弹出命令行窗口,输入命令【assoc .exe=exefile】并回车。
边栏推荐
- Distributed cache
- .class文件的字节码结构
- Value Function Approximation
- 基于GO语言实现的X.509证书
- uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
- Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
- Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
- Equals() and hashcode()
- equals()与hashCode()
- 三维扫描体数据的VTK体绘制程序设计
猜你喜欢

Data sharing of the 835 postgraduate entrance examination of software engineering in Hainan University in 23

AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06

Stm32f407 ------- DAC digital to analog conversion

Everyone is always talking about EQ, so what is EQ?

2021 SASE integration strategic roadmap (I)

Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100

37 pages Digital Village revitalization intelligent agriculture Comprehensive Planning and Construction Scheme

Mujoco Jacobi - inverse motion - sensor

The programmer resigned and was sentenced to 10 months for deleting the code. Jingdong came home and said that it took 30000 to restore the database. Netizen: This is really a revenge

How to set encoding in idea
随机推荐
用tkinter做一个简单图形界面
Compilation of kickstart file
The programmer resigned and was sentenced to 10 months for deleting the code. Jingdong came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
Leecode brush question record sword finger offer 56 - ii Number of occurrences of numbers in the array II
PXE server configuration
Data analysis course notes (III) array shape and calculation, numpy storage / reading data, indexing, slicing and splicing
2022/2/10 summary
Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
Operation test of function test basis
JS import excel & Export Excel
Encryption algorithm - password security
Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
Geo data mining (III) enrichment analysis of go and KEGG using David database
Stm32f407 ------- DAC digital to analog conversion
5种不同的代码相似性检测,以及代码相似性检测的发展趋势
Article management system based on SSM framework
Explain in detail the implementation of call, apply and bind in JS (source code implementation)
Advanced learning of MySQL -- Fundamentals -- concurrency of transactions
509 certificat basé sur Go
Levels - UE5中的暴雨效果