backup/restoration of files - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

backup/restoration of files

i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?

Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.

HELP


«1

Comments

  • zibadianzibadian Posts: 6,349Member
    : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    :
    : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    :
    : HELP
    :
    :
    :
    You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    [code]
    Source := TFileStream.Create(SourceFileName, fmOpenRead);
    Dest := TFileStream.Create(DestFileName, fmCreate);
    Dest.CopyFrom(Source, Source.Size);
    Dest.Free;
    Source.Free;
    [/code]
  • sarkiemarkiesarkiemarkie Posts: 89Member
    : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : :
    : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : :
    : : HELP
    : :
    : :
    : :
    : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : [code]
    : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : Dest := TFileStream.Create(DestFileName, fmCreate);
    : Dest.CopyFrom(Source, Source.Size);
    : Dest.Free;
    : Source.Free;
    : [/code]
    :


    How does the copyfile() API function work
  • zibadianzibadian Posts: 6,349Member
    : : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : : :
    : : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : : :
    : : : HELP
    : : :
    : : :
    : : :
    : : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : : [code]
    : : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : : Dest := TFileStream.Create(DestFileName, fmCreate);
    : : Dest.CopyFrom(Source, Source.Size);
    : : Dest.Free;
    : : Source.Free;
    : : [/code]
    : :
    :
    :
    : How does the copyfile() API function work
    :
    You provide 2 filenames, one for the source and one for the destination, and a boolean indicating if the destination should be overwritten. More info in the Windows API help.
  • sarkiemarkiesarkiemarkie Posts: 89Member
    : : : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : : : :
    : : : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : : : :
    : : : : HELP
    : : : :
    : : : :
    : : : :
    : : : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : : : [code]
    : : : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : : : Dest := TFileStream.Create(DestFileName, fmCreate);
    : : : Dest.CopyFrom(Source, Source.Size);
    : : : Dest.Free;
    : : : Source.Free;
    : : : [/code]
    : : :
    : :
    : :
    : : How does the copyfile() API function work
    : :
    : You provide 2 filenames, one for the source and one for the destination, and a boolean indicating if the destination should be overwritten. More info in the Windows API help.
    :
    can you do a bit of code like the other one. If its any help, one of the files is called "members.dat" and i want to copy it to removable storage.
  • zibadianzibadian Posts: 6,349Member
    : : : : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : : : : :
    : : : : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : : : : :
    : : : : : HELP
    : : : : :
    : : : : :
    : : : : :
    : : : : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : : : : [code]
    : : : : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : : : : Dest := TFileStream.Create(DestFileName, fmCreate);
    : : : : Dest.CopyFrom(Source, Source.Size);
    : : : : Dest.Free;
    : : : : Source.Free;
    : : : : [/code]
    : : : :
    : : :
    : : :
    : : : How does the copyfile() API function work
    : : :
    : : You provide 2 filenames, one for the source and one for the destination, and a boolean indicating if the destination should be overwritten. More info in the Windows API help.
    : :
    : can you do a bit of code like the other one. If its any help, one of the files is called "members.dat" and i want to copy it to removable storage.
    :
    The following code should copy (and overwrite existing) on the a:-drive:
    [code]
    CopyFile('members.dat', 'a:members.dat', true);
    [/code]
  • sarkiemarkiesarkiemarkie Posts: 89Member
    [b][red]This message was edited by sarkiemarkie at 2006-2-14 12:17:34[/red][/b][hr]
    : : : : : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : : : : : :
    : : : : : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : : : : : :
    : : : : : : HELP
    : : : : : :
    : : : : : :
    : : : : : :
    : : : : : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : : : : : [code]
    : : : : : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : : : : : Dest := TFileStream.Create(DestFileName, fmCreate);
    : : : : : Dest.CopyFrom(Source, Source.Size);
    : : : : : Dest.Free;
    : : : : : Source.Free;
    : : : : : [/code]
    : : : : :
    : : : :
    : : : :
    : : : : How does the copyfile() API function work
    : : : :
    : : : You provide 2 filenames, one for the source and one for the destination, and a boolean indicating if the destination should be overwritten. More info in the Windows API help.
    : : :
    : : can you do a bit of code like the other one. If its any help, one of the files is called "members.dat" and i want to copy it to removable storage.
    : :
    : The following code should copy (and overwrite existing) on the a:-drive:
    : [code]
    : CopyFile('members.dat', 'a:members.dat', true);
    : [/code]
    :

    is there any way to choose the place instead of hard coding it. Like choosing the place at run time



  • zibadianzibadian Posts: 6,349Member
    [b][red]This message was edited by zibadian at 2006-2-14 13:20:36[/red][/b][hr]
    : [b][red]This message was edited by sarkiemarkie at 2006-2-14 12:17:34[/red][/b][hr]
    : : : : : : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : : : : : : :
    : : : : : : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : : : : : : :
    : : : : : : : HELP
    : : : : : : :
    : : : : : : :
    : : : : : : :
    : : : : : : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : : : : : : [code]
    : : : : : : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : : : : : : Dest := TFileStream.Create(DestFileName, fmCreate);
    : : : : : : Dest.CopyFrom(Source, Source.Size);
    : : : : : : Dest.Free;
    : : : : : : Source.Free;
    : : : : : : [/code]
    : : : : : :
    : : : : :
    : : : : :
    : : : : : How does the copyfile() API function work
    : : : : :
    : : : : You provide 2 filenames, one for the source and one for the destination, and a boolean indicating if the destination should be overwritten. More info in the Windows API help.
    : : : :
    : : : can you do a bit of code like the other one. If its any help, one of the files is called "members.dat" and i want to copy it to removable storage.
    : : :
    : : The following code should copy (and overwrite existing) on the a:-drive:
    : : [code]
    : : CopyFile('members.dat', 'a:members.dat', true);
    : : [/code]
    : :
    :
    : is there any way to choose the place instead of hard coding it. Like choosing the place at run time
    :
    :
    Of course: using variables, or string properties from things like edit boxes, save and open dialogs, comboboxes, etc. You asked for an example, which you got based on the filename you gave. Remember that parameters don't necessarily be hard-coded.

    See also this thread:
    http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=4&MsgID=324987
  • sarkiemarkiesarkiemarkie Posts: 89Member
    : : [b][red]This message was edited by sarkiemarkie at 2006-2-14 12:17:34[/red][/b][hr]
    : : : : : : : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : : : : : : : :
    : : : : : : : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : : : : : : : :
    : : : : : : : : HELP
    : : : : : : : :
    : : : : : : : :
    : : : : : : : :
    : : : : : : : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : : : : : : : [code]
    : : : : : : : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : : : : : : : Dest := TFileStream.Create(DestFileName, fmCreate);
    : : : : : : : Dest.CopyFrom(Source, Source.Size);
    : : : : : : : Dest.Free;
    : : : : : : : Source.Free;
    : : : : : : : [/code]
    : : : : : : :
    : : : : : :
    : : : : : :
    : : : : : : How does the copyfile() API function work
    : : : : : :
    : : : : : You provide 2 filenames, one for the source and one for the destination, and a boolean indicating if the destination should be overwritten. More info in the Windows API help.
    : : : : :
    : : : : can you do a bit of code like the other one. If its any help, one of the files is called "members.dat" and i want to copy it to removable storage.
    : : : :
    : : : The following code should copy (and overwrite existing) on the a:-drive:
    : : : [code]
    : : : CopyFile('members.dat', 'a:members.dat', true);
    : : : [/code]
    : : :
    : :
    : : is there any way to choose the place instead of hard coding it. Like choosing the place at run time
    : :
    : :
    : Of course: using variables, or string properties from things like edit boxes, save and open dialogs, comboboxes, etc. You asked for an example, which you got based on the filename you gave. Remember that parameters don't necessarily be hard-coded.
    :
    you know if i put in an editbox, is there a way to bring up a little browse box in which the user can select a filepath? and then copy it
  • zibadianzibadian Posts: 6,349Member
    : : : [b][red]This message was edited by sarkiemarkie at 2006-2-14 12:17:34[/red][/b][hr]
    : : : : : : : : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : : : : : : : : :
    : : : : : : : : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : : : : : : : : :
    : : : : : : : : : HELP
    : : : : : : : : :
    : : : : : : : : :
    : : : : : : : : :
    : : : : : : : : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : : : : : : : : [code]
    : : : : : : : : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : : : : : : : : Dest := TFileStream.Create(DestFileName, fmCreate);
    : : : : : : : : Dest.CopyFrom(Source, Source.Size);
    : : : : : : : : Dest.Free;
    : : : : : : : : Source.Free;
    : : : : : : : : [/code]
    : : : : : : : :
    : : : : : : :
    : : : : : : :
    : : : : : : : How does the copyfile() API function work
    : : : : : : :
    : : : : : : You provide 2 filenames, one for the source and one for the destination, and a boolean indicating if the destination should be overwritten. More info in the Windows API help.
    : : : : : :
    : : : : : can you do a bit of code like the other one. If its any help, one of the files is called "members.dat" and i want to copy it to removable storage.
    : : : : :
    : : : : The following code should copy (and overwrite existing) on the a:-drive:
    : : : : [code]
    : : : : CopyFile('members.dat', 'a:members.dat', true);
    : : : : [/code]
    : : : :
    : : :
    : : : is there any way to choose the place instead of hard coding it. Like choosing the place at run time
    : : :
    : : :
    : : Of course: using variables, or string properties from things like edit boxes, save and open dialogs, comboboxes, etc. You asked for an example, which you got based on the filename you gave. Remember that parameters don't necessarily be hard-coded.
    : :
    : you know if i put in an editbox, is there a way to bring up a little browse box in which the user can select a filepath? and then copy it
    :
    You could place a "Browse" button (as seen in many programs) next to the edit box. In the OnClick() you can place a code like this:
    [code]
    if SelectDirectory('Select a folder', 'C:', s) then
    EditBox1.Text := s;
    [/code]
    With a little more coding, you can also use a TOpenDialog instead.
  • sarkiemarkiesarkiemarkie Posts: 89Member
    [b][red]This message was edited by sarkiemarkie at 2006-2-15 3:31:0[/red][/b][hr]
    : : : : [b][red]This message was edited by sarkiemarkie at 2006-2-14 12:17:34[/red][/b][hr]
    : : : : : : : : : : i know that to create a backup, i could make a new file identical to the onw i want to copy and then actually gather the data from the file and copy it all into the new one and therefore creating a backup but is there any easier way?
    : : : : : : : : : :
    : : : : : : : : : : Doing it the way i have explained is a lot of code and is very confusing. I mean, in windows, you could simply copy and paste the file and i was thinking along those lines.
    : : : : : : : : : :
    : : : : : : : : : : HELP
    : : : : : : : : : :
    : : : : : : : : : :
    : : : : : : : : : :
    : : : : : : : : : You could use the CopyFile() API function. Or you could open 2 TFileStream objects and call the CopyFrom() method. Here is the code for the stream variant:
    : : : : : : : : : [code]
    : : : : : : : : : Source := TFileStream.Create(SourceFileName, fmOpenRead);
    : : : : : : : : : Dest := TFileStream.Create(DestFileName, fmCreate);
    : : : : : : : : : Dest.CopyFrom(Source, Source.Size);
    : : : : : : : : : Dest.Free;
    : : : : : : : : : Source.Free;
    : : : : : : : : : [/code]
    : : : : : : : : :
    : : : : : : : :
    : : : : : : : :
    : : : : : : : : How does the copyfile() API function work
    : : : : : : : :
    : : : : : : : You provide 2 filenames, one for the source and one for the destination, and a boolean indicating if the destination should be overwritten. More info in the Windows API help.
    : : : : : : :
    : : : : : : can you do a bit of code like the other one. If its any help, one of the files is called "members.dat" and i want to copy it to removable storage.
    : : : : : :
    : : : : : The following code should copy (and overwrite existing) on the a:-drive:
    : : : : : [code]
    : : : : : CopyFile('members.dat', 'a:members.dat', true);
    : : : : : [/code]
    : : : : :
    : : : :
    : : : : is there any way to choose the place instead of hard coding it. Like choosing the place at run time
    : : : :
    : : : :
    : : : Of course: using variables, or string properties from things like edit boxes, save and open dialogs, comboboxes, etc. You asked for an example, which you got based on the filename you gave. Remember that parameters don't necessarily be hard-coded.
    : : :
    : : you know if i put in an editbox, is there a way to bring up a little browse box in which the user can select a filepath? and then copy it
    : :
    : You could place a "Browse" button (as seen in many programs) next to the edit box. In the OnClick() you can place a code like this:
    : [code]
    : if SelectDirectory('Select a folder', 'C:', s) then
    : EditBox1.Text := s;
    : [/code]
    : With a little more coding, you can also use a TOpenDialog instead.
    :
    i dont understand what "s" means or is used for. Is selectdirectory a variable?


«1
Sign In or Register to comment.