C# 获取文件扩展信息-应用名称/作者等
方案一:使用微乳封装的Shell包
添加nuget包:Microsoft.WindowsAPICodePack.Shell
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
1 string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "需求文档_迭代版_036.docx");
var file = ShellFile.FromFilePath(filePath); //Read and Write: string[] oldAuthors = file.Properties.System.Author.Value;
string oldTitle = file.Properties.System.Title.Value;
var orgAppName = file.Properties.System.ApplicationName; file.Properties.System.Author.Value = new string[] { "Author #1", "Author #2" };
file.Properties.System.Title.Value = "Example Title"; // Alternate way to Write: ShellPropertyWriter propertyWriter = file.Properties.GetPropertyWriter();
propertyWriter.WriteProperty(SystemProperties.System.Author, new string[] { "Author" });
propertyWriter.Close();
2 直接使用Shell32交互
添加Com组件引用:

List<string> arrHeaders = new List<string>();
List<Tuple<int, string, string>> attributes = new List<Tuple<int, string, string>>(); Shell32.Shell shell = new Shell32.Shell();
var strFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "需求文档_迭代版_036.docx"); Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));
Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName)); for (int i = ; i < short.MaxValue; i++)
{
string header = objFolder.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
arrHeaders.Add(header);
} // The attributes list below will contain a tuple with attribute index, name and value
// Once you know the index of the attribute you want to get,
// you can get it directly without looping, like this:
var Authors = objFolder.GetDetailsOf(folderItem, ); for (int i = ; i < arrHeaders.Count; i++)
{
var attrName = arrHeaders[i];
var attrValue = objFolder.GetDetailsOf(folderItem, i);
var attrIdx = i; attributes.Add(new Tuple<int, string, string>(attrIdx, attrName, attrValue)); Debug.WriteLine("{0}\t{1}: {2}", i, attrName, attrValue);
}
Console.ReadLine();
参考资料:
https://stackoverflow.com/questions/37869388/how-to-read-extended-file-properties-file-metadata
https://stackoverflow.com/questions/220097/read-write-extended-file-properties-c/2096315#2096315
https://stackoverflow.com/questions/24081665/windows-api-code-pack-where-is-it
https://www.codeproject.com/Articles/5036/ID3-Tag-Reader-Using-Shell-Functions
Windows API Code Pack 1.1.zip
https://github.com/jamie-pate/KeepSync/blob/master/contrib/Windows%20API%20Code%20Pack%201.1.zip
C# 获取文件扩展信息-应用名称/作者等的更多相关文章
- Web 在线文件管理器学习笔记与总结(11)获取文件夹信息 (12)返回上一级操作
(11)获取文件夹信息 文件夹没有修改操作. index.php: <?php require 'dir.func.php'; require 'file.func.php'; require ...
- PHP获取文件扩展名的多种方法
PHP获取文件扩展名的N种方法. 第1种方法: function get_extension($file) { substr(strrchr($file, '.'), 1): } 第2种方法: fun ...
- python获取文件扩展名的方法(转)
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...
- python获取文件扩展名的方法
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧 import os.path def file_extension(path): ] print file_ex ...
- 如何去掉drwxr-xr-x@中的@符号Linux文件扩展信息
如何去掉drwxr-xr-x@中的@符号Linux文件扩展信息ls -lart drwxrwxrwx@ 10 rlanffy staff 340B 3 6 2015 files-rwxrwxrwx@ ...
- Powershell 获取文件版本信息
获取文件版本信息,通过FileVersionInfo::GetVersioninfo(file) 来获取信息 function Check-DdpstoreFileVersion{ $Ddpstore ...
- PHP中获取文件扩展名的N种方法
PHP中获取文件扩展名的N种方法 从网上收罗的,基本上就以下这几种方式: 第1种方法:function get_extension($file){substr(strrchr($file, '.'), ...
- os.path.join合并 os.path.dirname返回上一级目录 os.path.exists(path) os.stat('path/filename')获取文件/目录信息
import os str1 = "grsdgfd" str2 = "wddf" str3 = "gddgs" # print(str1 + ...
- PHP获取文件扩展名五种以上的方法和注释
在PHP面试中或者考试中会有很大几率碰到写出五种获取文件扩展名的方法,下面是我自己总结的一些方法 $file = ‘需要进行获取扩展名的文件.php’; //第一种,根据.拆分,获取最后一个元素的值f ...
随机推荐
- option触发及获取当前选中的option值
#标签 #<select id="city" class="select"> #JavaScript #$("#city").c ...
- Locust性能模块浅谈
今天接触到Locust性能模块,下面介绍一下安装与简单的应用 1.安装方式:pip install Locust Locust支持Python 2.7, 3.4, 3.5, and 3.6的版本,小编 ...
- 《TensorFlow2深度学习》学习笔记(二)手动搭建并测试简单神经网络(附mnist.npz下载方式)
本实验使用了mnist.npz数据集,可以使用在线方式导入,但是我在下载过程中老是因为网络原因被打断,因此使用离线方式导入,离线包已传至github方便大家下载: https://github.com ...
- [AI] 切换cuda版本的万金油
1. 环境 ubuntu16.04 GTX1080Ti x 4 nvidia-418 cuda-10.1 pytorch1.0.0 目标:在最新的显卡驱动下,使用不同版本的cuda和深度学习框架来执行 ...
- 米勒罗宾素数检测(Miller-Rabin)
适用范围:较大数的较快素性判断 思路: 因为有好的文章讲解具体原理(见参考文章),这里只是把代码的大致思路点一下,读完了文章如果还有些迷糊,可以参考以下解释 原理是费马小定理:如果p是素数,则a^(p ...
- 类型擦除对Java调用Kotlin的影响
@JvmName: 扩展方法相关: 先来定义一个扩展方法: 好,接下来再来定义一个扩展函数: 此时报错了..看一下错误提示: 其中给的提示有点奇怪,第一个是很明显咱们的扩展函数木有接收参数嘛,为啥提示 ...
- python笔记39-unittest框架如何将上个接口的返回结果给下个接口适用(面试必问)
前言 面试必问:如何将上个接口的返回结果,作为下个接口的请求入参?使用unittest框架写用例时,如何将用例a的结果,给用例b使用. unittest框架的每个用例都是独立的,测试数据共享的话,需设 ...
- LGOJP3959 宝藏
题目链接 题目链接 题解 一开始想了一个错误的状压dp,水了40分. 这里先记录一下错误的做法: 错解: 设\(g[i,j,S]\)从\(i\)到\(j\),只经过集合\(S\)中的点的最短路,这个可 ...
- xshell连接不上阿里云服务器Could not connect to 'ip' (port 22): Connection failed.解决过程
记一次xshell阿里云服务器突然连接不上的解决办法: 1, 确认阿里云服务器安全组出入都有22,百度出来都说的这个和ip拦截设置,以防万一都设置了:但楼主设置后,还是连不上服务器: 只好下一步 2, ...
- LeetCode 875. Koko Eating Bananas
原题链接在这里:https://leetcode.com/problems/koko-eating-bananas/ 题目: Koko loves to eat bananas. There are ...