顯示具有 檔案路徑 標籤的文章。 顯示所有文章
顯示具有 檔案路徑 標籤的文章。 顯示所有文章

2018年12月17日 星期一

[C#]開啟資料夾 獲得資料夾路徑

Button--->中加入事件

FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
this.txtPath.Text = path.SelectedPath;

TextBox-->更改名稱 txtPath



測試環境 :c#

2018年11月29日 星期四

[C++]檢查檔案是否存在

C++ _access和_waccess的使用方法 
概述 
頭文件:<io.h> 判斷文件的訪問權限 
原型 
int _access( 
    const char *path,     int mode ); 
int _waccess(  
    const wchar_t *path,     int mode ); 
參數 
path 
文件或目錄路徑 
mode 
訪問權限設定 
返回值 
如果文件具有指定的訪問權限,則函數返回0;如果文件不存在或者不能訪問指定的權限,則返回-1。 
備註 
當path爲文件時,_access函數判斷文件是否存在,並判斷文件是否可以用
mode值指定的模式進行訪問。當path爲目錄時,_access只判斷指定的目錄是否存
在,在Windows NT和Windows 2000中,所有的目錄都有讀寫權限。 
mode的值和含義如下表所示: mode值 
檢查文件 

00 只檢查文件是否存在 
02 寫權限 
04 讀權限
06 讀寫權限 

_waccess是_access的寬字符版本,_waccess的參數path爲寬字符的字符串,
其他與_access相同。


CString FileName = L"C:\\123.txt";

int buf = 0;
buf = _waccess(FileName , 04);
if (buf != 0)
{
 AfxMessageBox(L"Files error");
 return false;
}

測試環境:MFC

[c++]MFC使用dlg 指定開啟資料夾獲取路徑

// Example code
CFolderPickerDialog m_dlg;
CString m_Folder;
 
m_dlg.m_ofn.lpstrTitle = _T("Put your title here");
m_dlg.m_ofn.lpstrInitialDir = _T("C:\\");
if (m_dlg.DoModal() == IDOK) {
       m_Folder = m_dlg.GetPathName();   // Use this to get the selected folder name 
                                         // after the dialog has closed
 
       // May need to add a '\' for usage in GUI and for later file saving, 
       // as there is no '\' on the returned name
       m_Folder += _T("\\");
       UpdateData(FALSE);   // To show updated folder in GUI
 
       // Debug
       TRACE("\n%S", m_Folder);
}
// End of example

測試環境:MFC

2018年7月12日 星期四

C#取得檔案名稱、路徑、副檔名、資料夾位置

using System.IO;


取得程式當下檔案目錄資訊:  string sPath = this.GetType().Assembly.Location;


string filename = @"C:\Users\123.text";
if (File.Exists(filename))
{
    MessageBox.Show("取得檔名(不包含附檔名)" + Path.GetFileNameWithoutExtension(filename));
    MessageBox.Show("取得副檔名:" + Path.GetExtension(filename));
    MessageBox.Show("目錄資料夾路徑:" + Path.GetDirectoryName(filename));
    MessageBox.Show("資料根目錄:" + Path.GetPathRoot(filename));
    MessageBox.Show("取得路徑:" + Path.GetFullPath(filename));
}

測試環境:c#.net 2015

2018年7月4日 星期三

[C#]獲取檔案路徑 彈出Dlg

建創一個元件TextBox 命名 tbox
using System.IO;



FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
this.tbox.Text = path.SelectedPath;



測試環境:VS2015 C#.NET

2018年6月4日 星期一

[C++]獲取檔案路徑、去除檔名

專案路徑↓

TCHAR path[MAX_PATH];
::GetModuleFileName(NULL, path, _MAX_PATH);//獲取檔案路徑
PathRemoveFileSpec(path);//去除檔名


測試環境:VS2015 MFC

[SQL]顯示千分位與小數顯示

  CONVERT ( data_type [ ( length ) ] , expression [ , style ] ) CONVERT style參數說明 1  (expression為 money 或 smallmoney型別): 0 : 預設,保留小數位後兩位,並四捨...