跳到主要內容

發表文章

目前顯示的是 1月, 2017的文章

%localappdata%

一般寫程式時會了將來除錯容易 通常會讓程式在執行過程中產生.log 檔案 若不想要讓end user看到這些檔案 我們可以將log產生在%localappdate%這個隱藏資料夾裡面 For example 實際路徑可能長這樣:  // C:\Users\User name\AppData\Local\MyProgram\DOTNETFX.log Sample code 如下:   CString dnetTagFilePath=getCurrentUserDirectory()+_T("\\DOTNETFX.log");   // C:\Users\User name\AppData\Local\MyProgram\DOTNETFX.log 定義getCurrentUserDirectory 並更改_stprintf (path, _T("%s\\ MyProgram "), path); CString CAppTools::getCurrentUserDirectory() {   CString szCurrentUserDirPath;   TCHAR path[MAX_PATH];   memset (path, 0, MAX_PATH*sizeof(TCHAR));   SHGetFolderPath (NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);   _stprintf (path, _T(" %s\\MyProgram "), path);   ::CreateDirectoryW (path, NULL);   szCurrentUserDirPath.Format(_T("%s"), path);   return szCurrentUserDirPath; }

[Python] Upload files to FTP

Assume we'd like to upload files to FTP:\\ 192.168.1.12\ Download storage\EXE\ from ftplib import FTP def upload_file_ToFTP ( filename ) : print 'upload:' , filename ftp . storbinary ( 'STOR Download storage \ \ EXE \ \ ' + os . path . basename ( filename ) , open ( filename , 'rb' ) ) #Initialize the FTP setting ftp = FTP ( '192.168.1.12' ) ftp . login ( user = 'OOXX' , passwd = 'SCRETE' ) #get the current working directory cwd = os . getcwd ( ) #get all files from the current working folder files_list = os . listdir ( cwd ) #upload files and skip directories for fn in files_list : #get the full path file name _fn = os.path.realpath(fn) #Skip directories if os . path . isdir ( _fn ) : print 'Skip dir:' , _fn continue upload_file_ToFTP ( _fn ) #upload process completed, close FTP connection ftp . close ( )

[C++]How to append text to a file

Append  text to a  file See below procedure: open file,   CStdioFile::Open Set the file pointer to the end of the file. CFile::SeekToEnd write a text CStdioFile::WriteString For example: CStdioFile file; if (file.Open(L "C:\\Set.cmd" , CFile :: modeNoTruncate | CFile :: modeWrite ))      file. SeekToEnd () ;                                                file.WriteString(_T( "Hello" )); else {        //show failed }