CopyFile Delphi 7
| Автор
| Сообщение |
Logan
Новичок

Зарегистрирован: 02.01.2007
Сообщения: 3
|
|
|
Цитата |
|
CopyFile( PChar(paramstr(0)), Pchar(paramstr(0)+'_'), false );
ReadFileStr( paramstr(0)+'_', fcontent );
DeleteFile( PChar(paramstr(0)+'_') );
IF exec THEN shellexecute( 0 , nil , Pchar(fname) , nil , nil , 1 );
Обьясните как переделать код чтобы он копировал файлы не в текущую деректорию а в папку Windows или на диск C:, после етого их запускал.
Пытался по разному никак невыходит  |
|
| В начало |
|
 |
|
|
 |
 NikotiN
Розовый мамонт

Возраст: 26
Знак зодиака: 
Зарегистрирован: 18.03.2005
Сообщения: 2137
|
|
|
Цитата |
|
CopyFile( Откуда, Куда, ВыводитьОшибкуЕслиУжеЕстьТакойФайл) _________________ Сила дурака в том, что умный перед ним бессилен. |
|
| В начало |
|
 |
Logan
Новичок

Зарегистрирован: 02.01.2007
Сообщения: 3
|
|
|
Цитата |
|
CopyFile( PChar(paramstr(0)), Pchar(paramstr(0)+'C:\'), false );
ReadFileStr( paramstr(0)+'C:\', fcontent );
DeleteFile( PChar(paramstr(0)+'C:\') );
так не работает почемуто |
|
| В начало |
|
 |
 Centurion
Постоянный участник

Зарегистрирован: 12.03.2006
Сообщения: 170
Откуда: Антарктида, мыс Надежда
|
|
|
Цитата |
|
to Logan
| Цитата: | | Обьясните как переделать код чтобы он копировал файлы не в текущую деректорию а в папку Windows или на диск C |
я лично ползуюсь данной функцией, лови код:
| delphi: | function WindowsCopyFile(FromFile, ToDir : string) : boolean; var F : TShFileOpStruct; begin F.Wnd := 0; F.wFunc := FO_COPY; FromFile:=FromFile+#0; F.pFrom:=pchar(FromFile); ToDir:=ToDir+#0; F.pTo:=pchar(ToDir); F.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION; result:=ShFileOperation(F) = 0; end;
|
а вызов таков:
| delphi: | if not WindowsCopyFile(GetCurrentDir+'\Unit1.pas', 'C:\') then ShowMessage('Проверьте путь к каталогу...');
|
| Цитата: | | после етого их запускал |
а эта тема уже была на форуме...
ЗЫ: Не забудь подключить ShellApi!
Добавлено спустя 1 час 43 минуты 41 секунду:
to Logan
НАДЕЮСЬ НЕ ВИРУСЫ ПИШЕШЬ... на лови код все равно делать нечего:
| delphi: | CopyFile(PChar(Paramstr(0)), PChar('c:\' + extractFilename(paramstr(0))), True); shellexecute(0, 'Open', PChar(extractFilename(paramstr(0))), '/runasis', 'c:\', sw_restore);
|
хммм... а вирь это идея... _________________ Qui non proficit, deficit. |
|
| В начало |
|
 |
Logan
Новичок

Зарегистрирован: 02.01.2007
Сообщения: 3
|
|
|
Цитата |
|
Undeclared identifier: 'extractFilename'
Я file joiner пытаюсь переписать
| delphi: | program stub; uses windows, shellAPI; //- add the strtoint() function ourselves and we save ~20KB on the filesize -// //- by not using Sysutils. -// function StrToInt(S: string): integer; begin Val(S, Result, Result); end; //- This lil function will blockread (read chunk by chunk) a file into one -// //- long string so we can manipulate it easily. -// procedure ReadFileStr(Fname:string;var FullContents:string); var Fcontents:File of Char; Fbuffer:array [1..1024] of Char; rLen,Fsize:LongInt; begin FullContents:=''; {$I-} (* ignore IO errors .. just quietly exit *) AssignFile(Fcontents,Fname); Reset(Fcontents); Fsize:=FileSize(Fcontents); while not Eof(Fcontents) do begin BlockRead(Fcontents,Fbuffer,1024,rLen); FullContents:=FullContents + string(Fbuffer); end; CloseFile(Fcontents); {$I+} if Length(FullContents) > Fsize then FullContents:=Copy(FullContents,1,Fsize); end; VAR fcontent, settings, fname, fset : String; i, fsize : integer; exec : boolean; f : textfile; //- the main part of the program -// begin (* copy the file, read it into a string, delete the copy *) CopyFile( PChar(paramstr(0)), Pchar(paramstr(0)+'_'), false ); ReadFileStr( paramstr(0)+'_', fcontent ); DeleteFile( PChar(paramstr(0)+'_') ); (* reset our variables *) i := length(fcontent); Settings := ''; (* extract the settings *) While (i>0) AND (fcontent[i] <> #00) DO begin Settings := fcontent[i] + settings; i := i-1; end; (* if there are no settings then close the program *) IF settings = '' THEN halt; (* remove the settings from our file string *) Delete( fcontent, i, length(settings) ); (* read the settings and start extracting the files 1x1 *) while pos(#01, settings) > 0 DO begin (* load the first settings form the settings buffer *) fset := copy( settings,1,pos(#01,settings)-1 ); (* remove the exctrated part from the settings buffer *) delete( settings,1,pos(#01,settings) ); (* filename is the first thing, with a 1 or 0 as the last character which says wether the file should be executed or not.. here we just extract the filename *) fname := copy( fset,1,pos(#02,fset)-2 ); (* if the last char of the filename is 1 then execute, if its 0 then don't *) exec := ( copy( fset,pos(#02,fset)-1,1) = '1'); (* delete the filename part form the settings part *) delete( fset,1,pos(#02,fset) ); (* all we're left with now is hte file size *) fsize := strtoint( fset ); (* create our file *) {$I-} AssignFile( F , fname ); Rewrite(f); (* add the files contents *) write( f, copy(fcontent,length(fcontent)-fsize,fsize) ); CloseFile(F); {$I+} (* remove the content from the end of our file buffer *) delete( fcontent, length(fcontent)-fsize, fsize ); (* execute if requested *) IF exec THEN shellexecute( 0 , nil , Pchar(fname) , nil , nil , 1 ); (* and carry on intil we have extracted all files *) end; (* thats it .. we're done .. now lets exit *) end.
|
|
|
| В начало |
|
 |
|
Новая тема
Ответить
Печать
|
Вы можете начинать темы Вы можете отвечать на сообщения Вы не можете редактировать свои сообщения Вы не можете удалять свои сообщения Вы не можете голосовать в опросах Вы не можете присоединять файлы в этом форуме Вы можете скачивать файлы в этом форуме
|
|