目的是想实现把一文件复制到U盘里去,目标U盘是通过ComboBox选择;但编译是...message "I/O error 21".... 请问该如何改正 ?代码如下...
procedure TForm1.Mycopyfile(a,b: string);
var
from,aa: file of byte;
buffer: array[0..4069]of char;
numread: integer;
filelength: longint;
begin
try
AssignFile(from,a);
Reset(from);
AssignFile(aa,b);
ReWrite(aa);
FileLength := filesize(from); //文件大小
except
Showmessage('文件复制错误!');
exit;
end;
with progressbar1 do
begin
min := 0;
position:=min;
max := filelength;
while filelength >0 do
begin
BlockRead(from,buffer[0],sizeof(buffer),numread);
filelength := filelength - numread;
BlockWrite(aa,buffer[0],numread);
position:= position + numread;
application.ProcessMessages;
end;
CloseFile(from);
CloseFile(aa);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i,DType:integer;
Disk:string;
begin
ProgressBar1.Hide;
for i:=65 to 90 do
begin
Disk:=chr(i)+':\';
DType := GetDriveType(PChar(Disk));
if DType = 5 then
ComboBox1.Items.Add(Format('%s %s',[Disk, '可移动磁盘']));
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ProgressBar1.Show;
mycopyfile('C:\bmp.bmp',Copy(ComboBox1.Text,1,3)+'bmp.bmp');
//mycopyfile('C:\bmp.bmp','J:\bmp.bmp')); 这样可以
Application.MessageBox('复制完毕! ','提示',MB_ICONASTERISK);
ProgressBar1.Hide ;
Edit3.Text:=Copy(ComboBox1.Text,1,3)+'bmp.bmp';
end;
解决方案 »
- TreeView中如何只显示目录及子目录,不显示文件
- 各位Delphi的前辈和后起之秀进!尤其杭州的朋友!
- 关于"窗体"和"ocx"(给点建议)
- 时间相加减的计算
- 提问:如何改变DBGRID选中单元的背景色
- 如何判断Edit控件是否有输入和没有输入?急!!!
- 我在程序中动态创建了一个Label控件,但不知道怎样实现它的OnClick事件,请高手赐教!!
- 同样的程序在单位可以运行,但在家里就提示找不到这个文件planner.res
- 要做一个地磅接口,sscom小程序能收到信息过来,问题是如何解码!
- 我怎样得到AdoStoreProc中返回的参数?
- 一个初级的问题,主帮忙指点!
- BDE连接ACCESS数据(急)
FileNames : array of string;procedure MyCopyFile(a,b : FileNames);
var
I : integer;
begin
//....
//....
with progressbar1 do
begin
for I := Low(a) to High(a) do
//.....
end;
end;