当前位置:网站首页>【批处理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】并回车。
边栏推荐
- Leetcode (547) - number of provinces
- Advantages and disadvantages of code cloning
- How to judge whether an element in an array contains all attribute values of an object
- Uniapp uploads and displays avatars locally, and converts avatars into Base64 format and stores them in MySQL database
- Mujoco finite state machine and trajectory tracking
- 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
- Advanced learning of MySQL -- basics -- multi table query -- self join
- 沉浸式投影在线下展示中的三大应用特点
- .class文件的字节码结构
- Leecode brushes questions to record interview questions 17.16 massagist
猜你喜欢

Racher integrates LDAP to realize unified account login

alexnet实验偶遇:loss nan, train acc 0.100, test acc 0.100情况

St table

Liuyongxin report | microbiome data analysis and science communication (7:30 p.m.)

37頁數字鄉村振興智慧農業整體規劃建設方案

Distributed cache

How to set encoding in idea

Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers

一图看懂对程序员的误解:西方程序员眼中的中国程序员

X.509 certificate based on go language
随机推荐
Article management system based on SSM framework
Advanced learning of MySQL -- Fundamentals -- concurrency of transactions
【JokerのZYNQ7020】AXI_EMC。
How to get started and improve test development?
.class文件的字节码结构
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
48 page digital government smart government all in one solution
代码克隆的优缺点
Mujoco second order simple pendulum modeling and control
Why should a complete knapsack be traversed in sequence? Briefly explain
Equals() and hashcode()
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
dynamic programming
stm32F407-------DAC数模转换
Meet the level 3 requirements of ISO 2.0 with the level B construction standard of computer room | hybrid cloud infrastructure
集合(泛型 & List & Set & 自定义排序)
Advanced learning of MySQL -- basics -- transactions
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
Basic information of mujoco