C#重命名文件夹下的文件
C#重命名文件夹下的文件
var files = System.IO.Directory.EnumerateFiles(desPath);
if(formatStr.Length == 0) {
formatStr = "{0}.jpg";
}
int count = 1;
foreach(String fileName in files) {
if (new System.IO.FileInfo(fileName).Length > 1024 * 75) {
System.IO.File.Move(fileName, System.IO.Path.Combine(desPath, String.Format(formatStr, count)));//对文件进行重命名
count++;
}
}
判断系统是否是win10
bool IsWindows10() {
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
string productName = (string)reg.GetValue("ProductName");
return productName.StartsWith("Windows 10");
}
获取桌面目录路径
String GetDesktopDirectory() {
return Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
}
创建新文件夹
void NewDirectory(String path) {
if(!System.IO.Directory.Exists(path)) {
System.IO.Directory.CreateDirectory(path);
}
}
base64编码
String GetBase64String() {
return Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(DateTime.Now.ToString()));
}
获取win10锁屏壁纸的缓存目录路径
public String GetWallPaperDirectory() {
String desPath = "";
String doc = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
doc = doc.Substring(0, doc.LastIndexOf("\\"));
String desTemp = System.IO.Path.Combine(doc, "AppData\\Local\\Packages");
var files = System.IO.Directory.EnumerateDirectories(desTemp);
foreach(String t in files) {
if(t.Contains("Microsoft.Windows.ContentDeliveryManager")) {
desPath = t;
break;
}
}
if(desPath.Length > 0) {
desPath = System.IO.Path.Combine(desPath, "LocalState\\Assets");
return desPath;
}
return "";
}
将文件复制并重命名到新路径
System.IO.File.Copy(fileName, System.IO.Path.Combine(newPath, String.Format(formatStr, count)));
修改控件字体,可以通过设置窗体的字体实现,因为继承关系,所以子控件的字体也会改变
ps : 链接10里面的一个评论很搞笑, 说答主用StartsWith("Windows 10");
不正确, 在Windows 100上判断会出错, 很有道理
pps : 感觉用C#写Demo比java方便, 主要是拖控件比较方便, 事件方法就在那里, 找一下就行了.
reference
-
[C#获取Windows系统特殊文件夹的路径转]
Updated: 2023-04-26 09:26
Created: 2017-04-10 01:33