public void SelectFolder(GameObject obj) { OpenDialogDir ofn2 = new OpenDialogDir(); ofn2.pszDisplayName = new string(new char[2000]);; // 存放目录路径缓冲区 ofn2.lpszTitle = "Open Project"; // 标题 //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框 IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2); char[] charArray = new char[2000]; for (int i = 0; i < 2000; i++) { charArray[i] = '\0'; } DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string fullDirPath = new String(charArray); fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); if (fullDirPath != "") { fullDirPath += "\\"; TargetFolderPath = fullDirPath; dicMEconfigLive["Out_Put_Path"] = TargetFolderPath; AppConfig.SaveConfigFile(Application.streamingAssetsPath + "/" + MEHoloConstant.LiveConfigFile, dicMEconfigLive); } }
public void OnChooseClick() { OpenDialogDir ofn2 = new OpenDialogDir(); ofn2.pszDisplayName = new string(new char[2000]);; // 存放目录路径缓冲区 ofn2.lpszTitle = "打开文件夹"; // 标题 //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框 IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2); char[] charArray = new char[2000]; for (int i = 0; i < 2000; i++) { charArray[i] = '\0'; } //获取路径 DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string fullDirPath = new String(charArray); //提取路径 fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); inputText.text = fullDirPath; choosePath = fullDirPath; }
/// <summary> /// 打开文件选择器 /// </summary> /// <param name="defaultPath">文件的完整路径</param> /// <param name="fileFilter"></param> /// <param name="title">Title</param> /// <returns></returns> public static string OpenFilePicker(string fileFilter, string defaultPath = "", string title = "选择文件") { string result = string.Empty; OpenFileName ofn = new OpenFileName(); ofn.structSize = System.Runtime.InteropServices.Marshal.SizeOf(ofn); ofn.filter = fileFilter; // "PPT Files(*.pptx;*.3dpx)\0*.pptx;*.3dpx"; char[] maxPathChar = new char[256]; //char[] pathChar = defaultPath.ToCharArray(); //for (int i = 0; i < pathChar.Length; i++) //{ // if (i < maxPathChar.Length) // { // maxPathChar[i] = pathChar[i]; // } //} ofn.file = new string(maxPathChar); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = string.IsNullOrEmpty(defaultPath) ? Application.dataPath : defaultPath; //默认路径 ofn.title = title; //ofn.defExt = "PPTX";//显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 /*| 0x00000200*/ | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR //浏览|文件必须存在|路径必须存在|允许选择多个文件|不改变当前路径 if (DllOpenFileDialog.GetOpenFileName(ofn)) { result = ofn.file; } return(result); }
public static string historyPath = ""; //记忆的路径 /// <summary> /// 加载外部图片 /// </summary> /// <param name="directoryName">填写GameConfigs里面的静态路径(例如pingmianPath)</param> public static void LoadSingleTexture(System.Action <Sprite, byte[]> callback) { OpenFileName openfilename = new OpenFileName(); openfilename.structSize = Marshal.SizeOf(openfilename); openfilename.filter = "图片文件(*.jpg*.png)\0*.jpg;*.png"; openfilename.file = new string(new char[256]); openfilename.maxFile = openfilename.file.Length; openfilename.fileTitle = new string(new char[64]); openfilename.maxFileTitle = openfilename.fileTitle.Length; string path = Application.streamingAssetsPath; path = path.Replace('/', '\\'); //默认路径 openfilename.initialDir = path; if (isLoadAllTextureFirst) { openfilename.initialDir = Application.streamingAssetsPath.Replace('/', '\\');//外部文件打开的路径 } else { openfilename.initialDir = historyPath.Replace('/', '\\'); } //添加路径记忆 //ofn.initialDir = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets"; openfilename.title = "Open Project"; openfilename.defExt = "JPG"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 openfilename.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllOpenFileDialog.GetSaveFileName(openfilename)) { //确定了图片的选择 Game.Instance.StartCoroutine(LoadSingleImage(openfilename.file, callback)); string[] newPath = openfilename.file.Split('\\'); for (int i = 0; i < newPath.Length - 1; i++) { historyPath += (newPath[i] + "\\"); } isLoadAllTextureFirst = false; } else { //点击的取消按键 } }
public static string FolderBrowserDlg(string defaultPath = "") { OpenDlgDir dlg = new OpenDlgDir(); dlg.pszDisplayName = defaultPath; dlg.ulFlags = BIF_USENEWUI; //设置hwndOwner==0时,是非模态对话框,设置hwndOwner!=0时为模态对话框 dlg.hwndOwner = DllOpenFileDialog.GetForegroundWindow(); IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(dlg); char[] charArray = new char[MAX_PATH_LENGTH]; DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string foldPath = new String(charArray); foldPath = foldPath.Substring(0, foldPath.IndexOf('\0')); return(foldPath); }
static public string GetFilePathByDialog(string title, string defaultPath) { OpenDialogFile openFileName = new OpenDialogFile(); openFileName.structSize = Marshal.SizeOf(openFileName); //openFileName.filter = "Excel文件(*.xlsx)\0*.xlsx"; openFileName.file = new string(new char[512]); openFileName.maxFile = openFileName.file.Length; openFileName.fileTitle = new string(new char[64]); openFileName.maxFileTitle = openFileName.fileTitle.Length; openFileName.initialDir = defaultPath; openFileName.title = title; openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008; DllOpenFileDialog.GetSaveFileName(openFileName); return(openFileName.file); }
public static string GetFileDir(string varTitle, string varpath) { OpenDialogFile openFile = new OpenDialogFile(); openFile.structSize = Marshal.SizeOf(openFile); //窗口标题 if (string.IsNullOrEmpty(varTitle)) { varTitle = "Open Project"; } openFile.title = varTitle; varpath = varpath.Replace('/', '\\'); //默认路径 openFile.initialDir = varpath; openFile.file = new string(new char[256]); openFile.maxFile = openFile.file.Length; openFile.fileTitle = new string(new char[256]); openFile.maxFileTitle = openFile.fileTitle.Length; //OpenDialogDir ofn2 = new OpenDialogDir(); //ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区 //if (string.IsNullOrEmpty(varTitle)) // ofn2.lpszTitle = "Open Project";// 标题 ////ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框 //IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2); //char[] charArray = new char[2000]; //for (int i = 0; i < 2000; i++) // charArray[i] = '\0'; //DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); //string fullDirPath = new String(charArray); //fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); //注意 一下项目不一定要全选 但是0x00000008项不要缺少 openFile.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllOpenFileDialog.GetOpenFileName(openFile)) { return(openFile.file); } return(null); }
private string OpenPath() { OpenDialogDir ofn2 = new OpenDialogDir(); ofn2.pszDisplayName = new string(new char[2000]);; // 存放目录路径缓冲区 ofn2.lpszTitle = "导出路径"; // 标题 //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框 IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2); char[] charArray = new char[2000]; for (int i = 0; i < 2000; i++) { charArray[i] = '\0'; } DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string path = new String(charArray); return(path); }
public static string OpenFile(string type = "All files(*.*)|*.*", string title = "选择") { DialogFile pth = new DialogFile(); pth.structSize = System.Runtime.InteropServices.Marshal.SizeOf(pth); pth.filter = type;// "All files(*.*)|*.*"; 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.dataPath; // default path pth.title = title; pth.defExt = "*.*"; pth.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllOpenFileDialog.GetOpenFileName(pth)) { string filepath = pth.file;//选择的文件路径; return(filepath); } return(null); }
public string OpenDir() { OpenDialogDir dir = new OpenDialogDir(); dir.pszDisplayName = new string(new char[2000]);; dir.lpszTitle = "选择播放目录"; IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(dir); char[] charArray = new char[2000]; for (int i = 0; i < 2000; i++) { charArray[i] = '\0'; } DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string fullDirPath = new String(charArray); fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); return(fullDirPath); }
static public string GetDirPathByDialog(string title) { OpenDialogDir odd = new GKFileUtil.OpenDialogDir(); odd.pszDisplayName = new string(new char[1000]); odd.lpszTitle = title; //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(odd); char[] charArray = new char[1000]; for (int i = 0; i < 1000; i++) { charArray[i] = '\0'; } DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string fullDirPath = new String(charArray); fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); return(fullDirPath); }
public static string OpenDir(string title = "选择") { DialogDir open = new DialogDir(); // 存放目录路径缓冲区 open.pszDisplayName = new string(new char[2000]); open.lpszTitle = title; //open.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框 IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(open); char[] charArray = new char[2000]; for (int i = 0; i < 2000; i++) { charArray[i] = '\0'; } DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string fullDirPath = new String(charArray); fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); return(fullDirPath); }
public static void OpenFilesPath(out string exportPath) { OpenDialogDir ofn2 = new OpenDialogDir(); ofn2.pszDisplayName = new string(new char[2000]);; // 存放目录路径缓冲区 ofn2.lpszTitle = "Open Project"; // 标题 //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框 IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2); char[] charArray = new char[2000]; for (int i = 0; i < 2000; i++) { charArray[i] = '\0'; } DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string fullDirPath = new String(charArray); fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); Debug.Log(fullDirPath);//这个就是选择的目录路径。 exportPath = fullDirPath; }
/// <summary> /// 弹窗选择文件夹 /// </summary> /// <returns></returns> public string getFilePath() { OpenDialogDir ofn2 = new OpenDialogDir(); ofn2.pszDisplayName = new string(new char[2000]);; // 存放目录路径缓冲区 ofn2.lpszTitle = "Open Folder"; // 标题 //ofn2.ulFlags = ofn2.BIF_EDITBOX; 崩溃 IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2); char[] charArray = new char[2000]; for (int i = 0; i < 2000; i++) { charArray[i] = '\0'; } DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray); string fullDirPath = new String(charArray); fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); return(fullDirPath); }
public static void OpenSingleFile(out string filepath, out string filename, params string[] exts) { bool flag = false; filepath = ""; filename = ""; OpenDialogFile ofn = new OpenDialogFile(); ofn.structSize = Marshal.SizeOf(ofn); //var str = string.Format("flie {0}(*.{1})|*.{2}", exts[0], exts[0], exts[0]); //if(exts.Length > 1) //{ // for(int i=1;i<exts.Length;++i) // { // str = string.Format("{0}|flie {1}(*.{2})|*.{3}", str, exts[i], exts[i], exts[i]); // } //} var str = "files(*." + exts[0]; if (exts.Length > 1) { for (int i = 1; i < exts.Length; ++i) { str = string.Format("{0};*.{1}", str, exts[i]); } } str = string.Format("{0})\0*.{1}", str, exts[0]); if (exts.Length > 1) { for (int i = 1; i < exts.Length; ++i) { str = string.Format("{0};*.{1}", str, exts[i]); } } //str += "\0All files (*.*)\0*.*"; ofn.filter = str; ofn.filterIndex = 1; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = "c:\\"; //默认路径 //ofn.defExt = null; //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllOpenFileDialog.GetOpenFileName(ofn)) { //StartCoroutine(WaitLoad(ofn.file));//加载图片到panle Debug.Log("Selected file with full path: {0}" + ofn.file); flag = true; } if (flag == true) { //System.Diagnostics.Process.Start(ofn.file); Debug.Log(ofn.file); filepath = ofn.file; Debug.Log(ofn.fileTitle); if (ofn.fileTitle != null) { string[] names = ofn.fileTitle.Split('.'); if (names.Length > 0) { filename = names[0]; } } } }