Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo

[es] :: C/C++ programiranje :: Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo

[ Pregleda: 5884 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

ower

Član broj: 136424
Poruke: 6
217.24.27.*



Profil

icon Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo02.04.2007. u 11:20 - pre 207 meseci
Kako uraditi, i da li je moguce uraditi program naravno u jeziku C koji ce kada se pokrene njegov exe. file, koji se nalazi npr. (u new folderu na C:\ particiji da se iskopira u My folder na D:\ particiji)...?
 
Odgovor na temu

Buffy
Stanko Culaja
Sipovo, BiH

Član broj: 45310
Poruke: 312
*.teol.net.



Profil

icon Re: Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo02.04.2007. u 12:07 - pre 207 meseci
Najjednostavnije je da koristis system funkciju:
Code:

#include <stdlib.h>

system("copy c:\\putanja\\fajl" d:\\putanja\\fajl");

 
Odgovor na temu

cume
Menadzer za visoko frekventnu naplatu u
maloprodajnom objektu

Član broj: 26038
Poruke: 315
*.telenor.co.yu.



+1 Profil

icon Re: Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo02.04.2007. u 12:49 - pre 207 meseci
Jos jednostavnije je da napise *.bat koji ce da radi isto to.
Bilo bi mnogo bolje da neko napise primer kako se to radi bez pozivanja vec gotovih programa kroz "system"...
Gde nestade taj edukativni duh [es]-a :-)

Pozdrav


 
Odgovor na temu

rumpl

Član broj: 54959
Poruke: 156
*.net81-66-199.noos.fr.



Profil

icon Re: Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo02.04.2007. u 19:29 - pre 207 meseci
Code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#define BUFF_SIZE 1024

int main(int argc, char **argv)
{
  int fd1;
  int fd2;
  int n;
  char *mem;
  
  if(argc != 2)
    {
      printf("Usage: ./main <file>\n");
      exit(0);
    }
  
  fd1 = open(argv[0], O_RDONLY);

  if(fd1 == -1)
    {
      printf("Error opening file %s\n", argv[0]);
      exit(-1);
    }

  if(access(argv[1], F_OK) == 0)
    {
      printf("Error, file exists: %s\n", argv[1]);
      exit(-1);
    }
  
  fd2 = open(argv[1], O_WRONLY|O_CREAT, 0644);
  
  if(fd2 == -1)
    {
      printf("Error opening file %s\n", argv[1]);
      exit(-1);
    }
  
  mem = malloc(BUFF_SIZE);

  while((n = read(fd1, mem, BUFF_SIZE)) != 0)
    {
      if(n == -1)
    {
      printf("Error reading file\n");
      exit(-1);
    }
      
      if(write(fd2, mem, n) == -1)
    {
      printf("Error writing to file\n");
      exit(-1);
    }

      memset(mem, '\0', BUFF_SIZE);
    }

  close(fd2);
  close(fd1);

  free(mem);

  return(0);
}


Za Linux
"The problem with the world is that everyone is a few drinks behind."
-Humphrey Bogart
 
Odgovor na temu

ower

Član broj: 136424
Poruke: 6
217.24.27.*



Profil

icon Re: Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo03.04.2007. u 13:50 - pre 207 meseci
Kako bih mogao da uradim neki program koji bi bio kompajliran na c:\ (particiji) i da prilikom pokretanja njegovog exe.file-a da se on automacki iskopira na particiji d:\ (npr:d:\New folder).Da li zna neko da mi pokaze gotov primer, na ovaj jednostavan programcic.

#include<stdio.h>
main()
{
printf("Zdravo svima");
}
 
Odgovor na temu

Nibble

Član broj: 63173
Poruke: 302
*.bc1.dlp27.bih.net.ba.



+1 Profil

icon Re: Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo03.04.2007. u 17:58 - pre 207 meseci
Evo ti jedan banalan primjer:

Code:


#include <windows.h>

#define szLokacija "D:\\New Folder\\Ime.exe"

int main()
{
 char szCurrPath[MAX_PATH];

 GetModuleFileName(GetModuleHandle(NULL),szCurrPath,MAX_PATH);

 if(!CopyFile(szCurrPath,szLokacija,TRUE))
 {
  MessageBox(0,"Greska pri kopiranju","Greska",0);
  return -1;
 }

 MessageBox(0,"Fajl je uspjesno kopiran","OK",0);

 return 0;

}



Sto se tice API funkcije pogledaj MSDN, a evo ti za svaki slucaj opis istih.

GetModuleHandle

Code:

The GetModuleHandle function returns a module handle for the specified module if the file has been mapped into the address space of the calling process. 

HMODULE GetModuleHandle(

    LPCTSTR lpModuleName     // address of module name to return handle for  
   );    
Parameters

lpModuleName

Points to a null-terminated string that names a Win32 module (either a .DLL or .EXE file). If the filename extension is omitted, the default library extension .DLL is appended. The filename string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process. 
If this parameter is NULL, GetModuleHandle returns a handle of the file used to create the calling process. 

Return Values

If the function succeeds, the return value is a handle to the specified module.
If the function fails, the return value is NULL. To get extended error information, call GetLastError. 


GetModuleFileName

Code:


Windows 95: The GetModuleFilename function will return long filenames when an application’s version number is greater than or equal to 4.00 and the long filename is available. Otherwise, it returns only 8.3 format filenames.

DWORD GetModuleFileName(

    HMODULE hModule,    // handle to module to find filename for 
    LPTSTR lpFilename,    // pointer to buffer for module path 
    DWORD nSize     // size of buffer, in characters 
   );    
Parameters

hModule

Identifies the module whose executable filename is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file used to create the calling process. 

lpFilename

Points to a buffer that is filled in with the path and filename of the given module. 

nSize

Specifies the length, in characters, of the lpFilename buffer. If the length of the path and filename exceeds this limit, the string is truncated. 

Return Values

If the function succeeds, the return value is the length, in characters, of the string copied to the buffer.
If the function fails, the return value is zero. To get extended error information, call GetLastError. 


CopyFile
Code:

The CopyFile function copies an existing file to a new file. 

BOOL CopyFile(

    LPCTSTR lpExistingFileName,    // pointer to name of an existing file 
    LPCTSTR lpNewFileName,    // pointer to filename to copy to 
    BOOL bFailIfExists     // flag for operation if file exists 
   );    
Parameters

lpExistingFileName

Points to a null-terminated string that specifies the name of an existing file. 

lpNewFileName

Points to a null-terminated string that specifies the name of the new file. 

bFailIfExists

Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds. 

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. 


Za MessageBox se snadji ;)

P.S. Potrazi takodje "Win32 SDK Reference Help"

Pozdrav

 
Odgovor na temu

[es] :: C/C++ programiranje :: Kako napraviti program koji ce kopirati exe. file sa jednog mesta na drugo

[ Pregleda: 5884 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.