Chertenok.ru - все о программировании
Вход  |  Регистрация  |  Поиск 
Праздник
Через 3 дня :

День славянской письменности и культуры


CopyFile Delphi 7


Новая тема  Ответить  Печать Предыдущая тема  Следующая тема
Автор Сообщение
Logan
Новичок




Зарегистрирован: 02.01.2007
Сообщения: 3

СообщениеВт, 02-Янв-2007 0:59    Заголовок сообщения: CopyFile Delphi 7
Цитата

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

СообщениеВт, 02-Янв-2007 18:59 
Цитата

CopyFile( Откуда, Куда, ВыводитьОшибкуЕслиУжеЕстьТакойФайл)
_________________
Сила дурака в том, что умный перед ним бессилен.
В начало
Посмотреть профиль Отправить личное сообщение
Logan
Новичок




Зарегистрирован: 02.01.2007
Сообщения: 3

СообщениеВт, 02-Янв-2007 22:26 
Цитата

CopyFile( PChar(paramstr(0)), Pchar(paramstr(0)+'C:\'), false );
ReadFileStr( paramstr(0)+'C:\', fcontent );
DeleteFile( PChar(paramstr(0)+'C:\') );
так не работает почемуто
В начало
Посмотреть профиль Отправить личное сообщение
Пол:Муж Centurion
Постоянный участник




Зарегистрирован: 12.03.2006
Сообщения: 170
Откуда: Антарктида, мыс Надежда
СообщениеСр, 03-Янв-2007 7:39 
Цитата

to Logan
Цитата:
Обьясните как переделать код чтобы он копировал файлы не в текущую деректорию а в папку Windows или на диск C

я лично ползуюсь данной функцией, лови код:
delphi:
  1. function WindowsCopyFile(FromFile, ToDir : string) : boolean;
  2. var F : TShFileOpStruct;
  3. begin
  4.   F.Wnd := 0; F.wFunc := FO_COPY;
  5.   FromFile:=FromFile+#0; F.pFrom:=pchar(FromFile);
  6.   ToDir:=ToDir+#0; F.pTo:=pchar(ToDir);
  7.   F.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION;
  8.   result:=ShFileOperation(F) = 0;
  9. end;

а вызов таков:
delphi:
  1. if not WindowsCopyFile(GetCurrentDir+'\Unit1.pas', 'C:\') then
  2.    ShowMessage('Проверьте путь к каталогу...');

Цитата:
после етого их запускал

а эта тема уже была на форуме...
ЗЫ: Не забудь подключить ShellApi!

Добавлено спустя 1 час 43 минуты 41 секунду:

to Logan
НАДЕЮСЬ НЕ ВИРУСЫ ПИШЕШЬ... Cool на лови код все равно делать нечего:
delphi:
  1. CopyFile(PChar(Paramstr(0)), PChar('c:\' + extractFilename(paramstr(0))), True);
  2. shellexecute(0, 'Open', PChar(extractFilename(paramstr(0))), '/runasis', 'c:\', sw_restore);

хммм... а вирь это идея...

_________________
Qui non proficit, deficit.
В начало
Посмотреть профиль Отправить личное сообщение Отправить e-mail
Logan
Новичок




Зарегистрирован: 02.01.2007
Сообщения: 3

СообщениеЧт, 04-Янв-2007 20:16 
Цитата

Undeclared identifier: 'extractFilename'

Я file joiner пытаюсь переписать :(


delphi:
  1. program stub;
  2.  
  3.  
  4. uses
  5.   windows,
  6.   shellAPI;
  7.  
  8. //- add the strtoint() function ourselves and we save ~20KB on the filesize -//
  9. //- by not using Sysutils.                                                  -//
  10.  function StrToInt(S: string): integer;
  11.  begin Val(S, Result, Result); end;
  12.  
  13. //- This lil function will blockread (read chunk by chunk) a file into one  -//
  14. //- long string so we can manipulate it easily.                             -//
  15.  
  16. procedure ReadFileStr(Fname:string;var FullContents:string);
  17. var
  18.  Fcontents:File of Char;
  19.  Fbuffer:array [1..1024] of Char;
  20.  rLen,Fsize:LongInt;
  21. begin
  22.  FullContents:='';
  23.  {$I-} (* ignore IO errors .. just quietly exit *)
  24.  AssignFile(Fcontents,Fname);
  25.  Reset(Fcontents);
  26.  Fsize:=FileSize(Fcontents);
  27.  while not Eof(Fcontents) do begin
  28.   BlockRead(Fcontents,Fbuffer,1024,rLen);
  29.   FullContents:=FullContents + string(Fbuffer);
  30.  end;
  31.  CloseFile(Fcontents);
  32.  {$I+}
  33.  if Length(FullContents) > Fsize then
  34.   FullContents:=Copy(FullContents,1,Fsize);
  35. end;
  36.  
  37. VAR
  38.  fcontent, settings, fname, fset : String;
  39.  i, fsize : integer;
  40.  exec : boolean;
  41.  f : textfile;
  42.  
  43. //- the main part of the program                                            -//
  44.  
  45. begin
  46.   (* copy the file, read it into a string, delete the copy *)
  47.   CopyFile( PChar(paramstr(0)), Pchar(paramstr(0)+'_'), false );
  48.   ReadFileStr( paramstr(0)+'_', fcontent );
  49.   DeleteFile( PChar(paramstr(0)+'_') );
  50.   (* reset our variables *)
  51.   i := length(fcontent);
  52.   Settings := '';
  53.   (* extract the settings *)
  54.   While (i>0) AND (fcontent[i] <> #00) DO begin
  55.    Settings := fcontent[i] + settings;
  56.    i := i-1;
  57.   end;
  58.   (* if there are no settings then close the program *)
  59.   IF settings = '' THEN halt;
  60.   (* remove the settings from our file string *)
  61.   Delete( fcontent, i, length(settings) );
  62.   (* read the settings and start extracting the files 1x1 *)
  63.   while pos(#01, settings) > 0 DO begin
  64.    (* load the first settings form the settings buffer *)
  65.    fset := copy( settings,1,pos(#01,settings)-1 );
  66.    (* remove the exctrated part from the settings buffer *)
  67.    delete( settings,1,pos(#01,settings) );
  68.    (* filename is the first thing, with a 1 or 0 as the last character
  69.    which says wether the file should be executed or not.. here we just
  70.    extract the filename *)
  71.    fname := copy( fset,1,pos(#02,fset)-2 );
  72.    (* if the last char of the filename is 1 then execute, if its 0 then don't *)
  73.    exec := ( copy( fset,pos(#02,fset)-1,1) = '1');
  74.    (* delete the filename part form the settings part *)
  75.    delete( fset,1,pos(#02,fset) );
  76.    (* all we're left with now is hte file size *)
  77.    fsize := strtoint( fset );
  78.    (* create our file *)
  79.    {$I-}
  80.    AssignFile( F , fname );
  81.    Rewrite(f);
  82.    (* add the files contents *)
  83.    write( f, copy(fcontent,length(fcontent)-fsize,fsize) );
  84.    CloseFile(F);
  85.    {$I+}
  86.    (* remove the content from the end of our file buffer *)
  87.    delete( fcontent, length(fcontent)-fsize, fsize );
  88.    (* execute if requested *)
  89.    IF exec THEN shellexecute( 0 , nil , Pchar(fname) , nil , nil , 1 );
  90.    (* and carry on intil we have extracted all files *)
  91.   end;
  92.   (* thats it .. we're done .. now lets exit *)
  93. end.
В начало
Посмотреть профиль Отправить личное сообщение
Показать сообщения:   
Страница 1 из 1
Перейти:  
Новая тема  Ответить  Печать

Вы можете начинать темы
Вы можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете голосовать в опросах
Вы не можете присоединять файлы в этом форуме
Вы можете скачивать файлы в этом форуме
хостинг от .masterhost 
Rambler's Top100