当前位置:网站首页>Unity operates on Explorer, opens explorer, selects files, and filters files
Unity operates on Explorer, opens explorer, selects files, and filters files
2022-07-26 22:19:00 【Unity tool man】
Open Explorer
Application.OpenURL(path);
Open selection file Filter file types ( as long as type Type of file display )
public void Openfile(string type)
{
OpenFileDlg pth = new OpenFileDlg();
pth.structSize = System.Runtime.InteropServices.Marshal.SizeOf(pth);
pth.filter = " file (*." + type + ")\0*." + type + "";// Filter file types
//pth.filter = " Picture file (*.jpg*.png)\0*.jpg;*.png";
pth.file = new string(new char[256]);
pth.maxFile = pth.file.Length;
pth.fileTitle = new string(new char[64]);
pth.maxFileTitle = pth.fileTitle.Length;
pth.initialDir = Application.streamingAssetsPath.Replace('/', '\\'); // default path
pth.title = " Select project json";
pth.defExt = "JPG";// Show file type
pth.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
if (OpenFileDialog.GetOpenFileName(pth))
{
string filepath = pth.file;// Selected file path ;
DirectoryInfo i = new DirectoryInfo(filepath);
// Superior directory
string path = i.Parent.FullName;// Return the parent directory of the file
ProjectData openprodata = new ProjectData();
openprodata.proname = Path.GetFileNameWithoutExtension(path);// Return the last folder name of the path
}
using System;
using System.Runtime.InteropServices;
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
public class OpenFileDlg
{
public int structSize = 0;
public IntPtr dlgOwner = IntPtr.Zero;
public IntPtr instance = IntPtr.Zero;
public String filter = null;
public String customFilter = null;
public int maxCustFilter = 0;
public int filterIndex = 0;
public String file = null;
public int maxFile = 0;
public String fileTitle = null;
public int maxFileTitle = 0;
public String initialDir = null;
public String title = null;
public int flags = 0;
public short fileOffset = 0;
public short fileExtension = 0;
public String defExt = null;
public IntPtr custData = IntPtr.Zero;
public IntPtr hook = IntPtr.Zero;
public String templateName = null;
public IntPtr reservedPtr = IntPtr.Zero;
public int reservedInt = 0;
public int flagsEx = 0;
}
public class OpenFileDialog
{
[DllImport("Comdlg32.dll",SetLastError=true,ThrowOnUnmappableChar=true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([ In, Out ] OpenFileDlg ofd );
}

original text :https://blog.csdn.net/qq_38834505/article/details/99826830
Add :
OpenFileDialog Dialog box Filter Attribute specification :
Let's start with an example , Look at the Filter The composition of attributes :“ Excel file |.xls ”, Ahead “Excel file ” Become a label , It's a readable string , You can define ,“|.xls” Is filter , Indicates that the suffix in the filter folder is .xls The file of ,“*” Represents a match Excel String of file name .
OK, Let's talk about several situations we often use :
1. Filter yes null or Empty, Show all files , And always show folders
2. Need to filter specific files , Set up Filter The attribute is “ label |*. suffix ”, Set according to this format , Tags can be customized , Is a string , Suffixes indicate the file suffixes you need to filter , for example “.txt、.doc” etc.
3. You need to filter a variety of files , For example, you need to filter image files , But there are several suffixes for picture files , for example jpg、png、gif etc. , When you need to filter these files at the same time , Set up Filter The attribute is “ label |.jpg;.png;*.gif”, Be careful : Just add a few more suffixes to the filter , Use semicolons to separate different suffixes
4. When you need to filter multiple files , But don't list them all at the same time , Only when the user selects the required file type through the drop-down list , Before screening . In this case, you only need to set a few more filters ,filter The properties are set as follows :“ label 1|*.jpg| label 2|.png| label 3|.gif”. Be careful : Use between different filters “|” Just separate .
Filter Attributes are similar to regular expressions , The trial * Represents the character that matches the file name , Use “. suffix ” Match the suffix of the file , By connecting suffixes ( The trial ; No. separates the suffixes you need ) It means to filter all files matching the suffix at the same time , adopt “|” Connecting different filters means that the user selects the suffix name to filter files
private void btnupload_Click(object sender, EventArgs e)
{
using (OpenFileDialog open = new OpenFileDialog())
{
open.Multiselect = false;
open.Title = " Open file ";
open.Filter = " picture |*.jpg;*.png;*.gif;*.jpeg;*.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
}
}
}
边栏推荐
- Go----Go语言中的变量使用方法
- 软件测试技术之跨平台的移动端UI自动化测试(下)
- Promise me, don't write shit code after reading it..
- Go----Go 语言中的标识符和关键字
- Is it safe to open an account for flush mobile stock trading? How to open an account
- xshell7个人免费下载,使用
- : could not determine a constructor for the tag ! RootAdmin
- easyui datagrid 获取多条选中的数据进行操作
- AFNetworking了解
- : could not determine a constructor for the tag !RootAdmin
猜你喜欢

Leetcode exercise - Sword finger offer II 005. maximum product of word length

The potential of emerging markets is unlimited, and advance.ai risk control products help Chinese offshore enterprises build a solid foundation for safe development

Flink's real-time data analysis practice in iFLYTEK AI marketing business

小白学习MySQL - Derived Table

Operating guidelines and suggestions for spot gold (Part 1)

想让照片中的云飘起来?视频编辑服务一键动效3步就能实现

07 df 命令

yolov1

Understanding and practice of the trend of Bank of London foreign exchange

知识库工具 | 微网站、文档中心、形象展示页拖拽即可生成(附模板,直接用)
随机推荐
Instructions for use of light source controller dial switch
Excel-vba quick start (XI. Common string operations)
判断numpy array数组的维数
Pytorch--Visdom使用
Understanding and practice of the trend of Bank of London foreign exchange
Difference between D and C
AFNetworking了解
When deploying Flink on a single machine and creating the connection table of oracle19c RAC, the error ora-12505 is reported. Who can help
View绘制流程1-View与Window的关系
Determine the dimension of numpy array array
[horizon sunrise X3 sect trial experience] + unpacking post
Li Kou daily question - day 43 -168. Name of Excel table column
What you need to know about mobile video compatibility
JS 延迟执行window.onload
matlab 画短时能量图
【C语言基础】17 链表初探
JMeter -- response Chinese garbled code processing
09 expr command
Concept and classification of processes
Excel VBA quick start (XII. Common usage of like comparison)