2017年11月30日 星期四
[Windows][C/C++] 如何得知Windows中資料夾內的檔案是否被修改(修改時間)
目標是偵測某個資料夾底下的檔案是否有被修改過?可以透過讀取檔案的Last modified time
在Windows底下可以呼叫system API: GetFileTime() function:
API說明可到MSDN:
https://msdn.microsoft.com/zh-tw/library/windows/desktop/ms724320(v=vs.85).aspx
透過這個API可以將檔案的下列三種時間:
1. Create time,
2. Last access time,
3. Last write time
檔案是否有被動過?包含幾種狀況
1. 被修改內容且存檔
2. 檔案被(另外的檔案)覆蓋
3. 檔案被刪除
4. 修改檔名
3跟4是有點像, 4的話原來檔案也等於是刪除,變成新增另外一個檔案的感覺
2016年10月20日 星期四
如何在Visual Studio中使用Boost C++ Library
1. 環境版本,取得Boost
本文使用目前Boost最新版
下載後為一個zip壓縮檔,解開後內容如下圖:

資料夾說明如下: (Copy from user manual)
*************************************************
boost_1_62_0\ .................The “boost root directory”
index.htm .........A copy of www.boost.org starts here
boost\ .........................All Boost Header files
lib\ .....................precompiled library binaries
libs\ ............Tests, .cpps, docs, etc., by library
index.html ........Library documentation starts here
algorithm\
any\
array\
…more libraries…
status\ .........................Boost-wide test suite
tools\ ...........Utilities, e.g. Boost.Build, quickbook, bcp
more\ ..........................Policy documents, etc.
doc\ ...............A subset of all Boost library docs
*************************************************
Boost Library 有兩種方式給你用
1. 不需要Build: (Header Only)
大部分Lib只需要include Header就行了, Library code都寫在header
所以你用了之後跟你的code一起Build就行了, (Templete & inline functions)
2. 需要Build:
一些需要先build, 如下: 跟系統有關的
有了上面說明,就可以很容易知道怎麼用Boost,
對於不用build的Lib,只要include header就行了
此處以一個Win32 console program為例,要做的設定基本上只要去專案中
加入boost的路徑就行了:
加入Boost的路徑可能如下,或者看你是放在哪裡?
C:\Program Files\boost\boost_1_62_0
Property\Configuration Property\C/C++\General\Additional Include Directories

4. 簡單範例: 使用boost/array
下面這段code 來測試使用boost, (我隨便寫寫...有compiler過沒問題)
主要是宣告一個boost int array, 大小10
全部填入3, 然後print出來
**************************************
#include "stdafx.h"
#include <boost/array.hpp>
using namespace boost;
int _tmain(int argc, _TCHAR* argv[])
{
boost::array<int, 10> a;
a.fill( 3);
for( int i = 0; i < a.size(); i++ )
printf( " %d \n ", a[i] );
return 0;
}
*****************************************
這個是Boost中 container 的static array, 用法可參考Boost線上說明
http://www.boost.org/doc/libs/1_62_0/doc/html/array.html
完畢!
本文使用目前Boost最新版
- Boost C++ Library 最新版(2016.9) V1.62
- VisualStudio 2010
- Windows 7
下載後為一個zip壓縮檔,解開後內容如下圖:
資料夾說明如下: (Copy from user manual)
*************************************************
boost_1_62_0\ .................The “boost root directory”
index.htm .........A copy of www.boost.org starts here
boost\ .........................All Boost Header files
lib\ .....................precompiled library binaries
libs\ ............Tests, .cpps, docs, etc., by library
index.html ........Library documentation starts here
algorithm\
any\
array\
…more libraries…
status\ .........................Boost-wide test suite
tools\ ...........Utilities, e.g. Boost.Build, quickbook, bcp
more\ ..........................Policy documents, etc.
doc\ ...............A subset of all Boost library docs
*************************************************
Boost Library 有兩種方式給你用
1. 不需要Build: (Header Only)
大部分Lib只需要include Header就行了, Library code都寫在header
所以你用了之後跟你的code一起Build就行了, (Templete & inline functions)
2. 需要Build:
一些需要先build, 如下: 跟系統有關的
- Boost.Chrono
- Boost.Context
- Boost.Filesystem
- Boost.GraphParallel
- Boost.IOStreams
- Boost.Locale
- Boost.MPI
- Boost.ProgramOptions
- Boost.Python (see the Boost.Python build documentation before building and installing it)
- Boost.Regex
- Boost.Serialization
- Boost.Signals
- Boost.System
- Boost.Thread
- Boost.Timer
- Boost.Wave
有了上面說明,就可以很容易知道怎麼用Boost,
對於不用build的Lib,只要include header就行了
此處以一個Win32 console program為例,要做的設定基本上只要去專案中
加入boost的路徑就行了:
加入Boost的路徑可能如下,或者看你是放在哪裡?
C:\Program Files\boost\boost_1_62_0
Property\Configuration Property\C/C++\General\Additional Include Directories
4. 簡單範例: 使用boost/array
下面這段code 來測試使用boost, (我隨便寫寫...有compiler過沒問題)
主要是宣告一個boost int array, 大小10
全部填入3, 然後print出來
**************************************
#include "stdafx.h"
#include <boost/array.hpp>
using namespace boost;
int _tmain(int argc, _TCHAR* argv[])
{
boost::array<int, 10> a;
a.fill( 3);
for( int i = 0; i < a.size(); i++ )
printf( " %d \n ", a[i] );
return 0;
}
*****************************************
這個是Boost中 container 的static array, 用法可參考Boost線上說明
http://www.boost.org/doc/libs/1_62_0/doc/html/array.html
完畢!
2015年9月14日 星期一
在 Windows 7 64 bit 上使用 Sikuli Script
2015/9.15
GUI, 人機介面怎麼測試,發現了好玩的東西~
紀錄一下測試的步驟:
環境: MS Windows 7 64bit
Sikuli (西酷吏, 自己亂翻)
視覺化的程式語法,可以模擬使用者在桌面上用滑鼠跟鍵盤的操作
所以對於我們要用來做測試的話是相當的方便
Step1. 下載軟體 (Windows version):
Java run-time environments: (必須安裝 Version 6 )
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#jre-6u30-oth-JPR
沒有Jave 無法正常使用 Sikuli IDE and Setup.
我偏好免安裝版:
https://launchpad.net/sikuli/sikulix/x1.0-rc3/+download/Sikuli-X-1.0rc3%20%28r905%29-win32.zip
安裝包:
https://launchpad.net/sikuli/sikulix/1.0.1/+download/sikuli-setup.jar
Step2. 安裝執行
解壓縮後執行sikuli-setup.jar
啟動IDE: Sikuli-IDE-w.bat (批次檔的內容必須正確指定到JRE6的路徑)
這邊常見的問題是,啟動Sikuli-IDE後要截圖會失敗,我是看這一篇解決問題滴:
https://bugs.launchpad.net/sikuli/+bug/893772
Step3. 開始Program...
官網:
http://www.sikuli.org/
GUI, 人機介面怎麼測試,發現了好玩的東西~
紀錄一下測試的步驟:
環境: MS Windows 7 64bit
Sikuli (西酷吏, 自己亂翻)
視覺化的程式語法,可以模擬使用者在桌面上用滑鼠跟鍵盤的操作
所以對於我們要用來做測試的話是相當的方便
Step1. 下載軟體 (Windows version):
Java run-time environments: (必須安裝 Version 6 )
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#jre-6u30-oth-JPR
沒有Jave 無法正常使用 Sikuli IDE and Setup.
我偏好免安裝版:
https://launchpad.net/sikuli/sikulix/x1.0-rc3/+download/Sikuli-X-1.0rc3%20%28r905%29-win32.zip
安裝包:
https://launchpad.net/sikuli/sikulix/1.0.1/+download/sikuli-setup.jar
Step2. 安裝執行
解壓縮後執行sikuli-setup.jar
啟動IDE: Sikuli-IDE-w.bat (批次檔的內容必須正確指定到JRE6的路徑)
這邊常見的問題是,啟動Sikuli-IDE後要截圖會失敗,我是看這一篇解決問題滴:
https://bugs.launchpad.net/sikuli/+bug/893772
Step3. 開始Program...
官網:
http://www.sikuli.org/
2013年4月2日 星期二
XSD 簡介, a XML Schema (一)
### This article is reference to : w3schools.com ###
XML schema 是用來描述XML的內容
目前有兩種方式來描述XML的內容結構:
1. DTDs
2. XML schema (xsd)
XML schema 比 DTD 好,因為schema的擴充性高且支援 Data type
以下是一 XML schema (以下簡稱 xsd ) 範例:
a simple XML name: "note.xml"
這個是上面 note.xml 的 xsd 描述
1. 由上可知 xsd 本身也是一個 XML, (用一個XML來描述另一個XML的結構)
2. 可以定義XML中有那些 elements
3. 定義 有哪些 attributes
4. 定義 那些 elements 是 child elements
5. 定義 child element 之間的順序關係
6. 定義 element 的內容是否 empty 或有文字(Text)內容
7. 定義 資料型態(data type)
8. 定義 element 或 attributes 的 default value 或 fixed value
下面這個 XML 內容可以 reference "note.xsd" (加入藍色的部分)
基本 xsd 框架如下:
<名詞解釋> simple element / complex element
XSD simple element: 表示這個element 的內容頂多只能是文字,不能有其他element ,不能有其他attribute。
不滿足以上條件的都是 complex element
下面這個範例就是 simple element, 其element 的內容頂多是文字
下面這個範例,element 有 attribute, 所以他就是 complex type
如何使用xsd 描述 simple type:
xsd 如下範例:
<xs:element name="xxx" type="yyy"/>
xxx is name of element
yyy is data type of the element
xsd 有許多內建的 data type, 下面是依些常見的
前面有提到 xsd 還可以定義 element 的 default value 或 fixed value
範例如下:
<xs:element name="color" type="xs:string" default="red"/>
<xs:element name="color" type="xs:string" fixed="red"/>
xsd 如何描述 attribute: 範例如下: (和描述 simple type element 很像)
<xs:attribute name="xxx" type="yyy"/>
<xs:attribute name="lang" type="xs:string" default="EN"/>
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
Attribute對於element 來說,有時候是 optional,有時候是 Must
像上面的範例沒特別說明,表示 optional
若是 must
<xs:attribute name="lang" type="xs:string" use="required"/>
************************************************************
我們也可以對 element 或 attribute 的內容做規範限制 (Restrictions)
下面這個範例 我們對 "age" element 的內容作一些 restrictions
age 的base = integer, 最小值 0, 最大值 120
待續...
XML schema 是用來描述XML的內容
目前有兩種方式來描述XML的內容結構:
1. DTDs
2. XML schema (xsd)
XML schema 比 DTD 好,因為schema的擴充性高且支援 Data type
以下是一 XML schema (以下簡稱 xsd ) 範例:
a simple XML name: "note.xml"
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
這個是上面 note.xml 的 xsd 描述
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
1. 由上可知 xsd 本身也是一個 XML, (用一個XML來描述另一個XML的結構)
2. 可以定義XML中有那些 elements
3. 定義 有哪些 attributes
4. 定義 那些 elements 是 child elements
5. 定義 child element 之間的順序關係
6. 定義 element 的內容是否 empty 或有文字(Text)內容
7. 定義 資料型態(data type)
8. 定義 element 或 attributes 的 default value 或 fixed value
下面這個 XML 內容可以 reference "note.xsd" (加入藍色的部分)
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
基本 xsd 框架如下:
<?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
<名詞解釋> simple element / complex element
XSD simple element: 表示這個element 的內容頂多只能是文字,不能有其他element ,不能有其他attribute。
不滿足以上條件的都是 complex element
下面這個範例就是 simple element, 其element 的內容頂多是文字
<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>
下面這個範例,element 有 attribute, 所以他就是 complex type
<lastname lang="EN">Smith</lastname>
如何使用xsd 描述 simple type:
xsd 如下範例:
<xs:element name="lastname" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>
<xs:element name="xxx" type="yyy"/>
xxx is name of element
yyy is data type of the element
xsd 有許多內建的 data type, 下面是依些常見的
- xs:string
- xs:decimal
- xs:integer
- xs:boolean
- xs:date
- xs:time
前面有提到 xsd 還可以定義 element 的 default value 或 fixed value
範例如下:
<xs:element name="color" type="xs:string" default="red"/>
<xs:element name="color" type="xs:string" fixed="red"/>
xsd 如何描述 attribute: 範例如下: (和描述 simple type element 很像)
<xs:attribute name="xxx" type="yyy"/>
<xs:attribute name="lang" type="xs:string" default="EN"/>
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
Attribute對於element 來說,有時候是 optional,有時候是 Must
像上面的範例沒特別說明,表示 optional
若是 must
<xs:attribute name="lang" type="xs:string" use="required"/>
************************************************************
我們也可以對 element 或 attribute 的內容做規範限制 (Restrictions)
下面這個範例 我們對 "age" element 的內容作一些 restrictions
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
age 的base = integer, 最小值 0, 最大值 120
待續...
訂閱:
文章 (Atom)