这段时间作毕设,老是拿着U盘到处跑,很累。
有时候,就是一不小心,自己在电脑上做好了,到了导师那里总是出现莫名其妙的错误,奇怪!这个地方我明明修改好了,为了到了这里还出错?奇了!
导师为此很生气,“你上次来的时候就是这里出错,想不到过了一个星期竟然还没改正!这几天你干什么了!”
我冤死,我。。。。
其实,我最新做出来的东西没拷出来,还在我电脑上放着呢。我日!
想了想,怎么办?自己做一个得了,貌似我在网上还没听过这类工具呢。搜U盘就是一大堆的U盘病毒或者专杀工具之类的,都说现在网络很方便,怎么随便一个小工具都得自己亲自动手啊,没天理了。。。
这几天忙毕设忙得要死,还得准备随时会来的清考。。。
没时间了,上网查了一点资料,最核心的部分找到了,先放出来,等日后空闲了再补上这一块,或者兄弟你有时间就帮我一把,现在把最核心的部分放出来。
这里是单元部分的代码,采用的是Delphi语言,其实C++也是一样的,反正都是调用Windows API。

Code
1
unit Main;
2
3
interface
4
5
uses
6
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7
Dialogs, Buttons, StdCtrls, ExtCtrls;
8
9
type
10
TForm1 = class(TForm)
11
OpenDialog1: TOpenDialog;
12
Edit1: TEdit;
13
Label1: TLabel;
14
SpeedButton1: TSpeedButton;
15
SpeedButton2: TSpeedButton;
16
txtAge: TLabeledEdit;
17
procedure SpeedButton1Click(Sender: TObject);
18
procedure SpeedButton2Click(Sender: TObject);
19
private
20
{ Private declarations }
21
public
22
{ Public declarations }
23
end;
24
25
var
26
Form1: TForm1;
27
28
implementation
29
30
{$R *.dfm}
31
32
procedure TForm1.SpeedButton1Click(Sender: TObject);
33
begin
34
if self.OpenDialog1.Execute then
35
Edit1.Text := self.OpenDialog1.FileName;
36
end;
37
38
procedure TForm1.SpeedButton2Click(Sender: TObject);
39
var
40
t: Integer;//获得文件对标准开始(貌似是1970年)的秒数
41
begin
42
t := FileAge(Edit1.Text);
43
//格式化成为标准时间格式
44
txtAge.Text := DateTimeToStr(FileDateToDateTime(t));
45
end;
这里是窗体部分的代码:

Code
object Form1: TForm1
Left = 244
Top = 189
BorderStyle = bsDialog
Caption = 'Form1'
ClientHeight = 123
ClientWidth = 573
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 24
Top = 24
Width = 84
Height = 13
Caption = #25991#20214#20840#36335#24452#21517#65306
end
object SpeedButton1: TSpeedButton
Left = 462
Top = 19
Width = 89
Height = 25
Caption = #25171#24320#25991#20214
OnClick = SpeedButton1Click
end
object SpeedButton2: TSpeedButton
Left = 462
Top = 72
Width = 89
Height = 25
Caption = #33719#24471#20462#25913#26102#38388
OnClick = SpeedButton2Click
end
object Edit1: TEdit
Left = 120
Top = 20
Width = 321
Height = 21
TabOrder = 0
end
object txtAge: TLabeledEdit
Left = 120
Top = 72
Width = 321
Height = 21
EditLabel.Width = 93
EditLabel.Height = 13
EditLabel.Caption = #25991#20214#20462#25913#26102#38388#65306' '
LabelPosition = lpLeft
TabOrder = 1
end
object OpenDialog1: TOpenDialog
Filter = 'XML'#25991#20214'|*.xml|'#25152#26377#25991#20214'|*.*'
Left = 258
Top = 42
end
end
把上面的两个分别保存成pas和dfm文件,然后调用就可以看到效果了。下面是我做出来的效果:

我的想法就是通过计算文件的修改事件来获得是从U盘拷出来还是从电脑拷到U盘上去,至于其他的,不难了吧。。
已经找到同步工具,暂时不考虑这个问题了!