f



File IO/Copy A File

I am stumped on this one...

Any easy way to copy a file from a button event in RB 5.2?  I
basically want the button to copy DB.rdb to DB.bak.  THis way is
someone hozes the file, we have a backup.

Thanks in advance,

SJ
0
shanejudy
5/29/2004 8:19:00 PM
comp.lang.basic.realbasic 2744 articles. 0 followers. spam127 (8) is leader. Post Follow

2 Replies
809 Views

Similar Articles

[PageSpeed] 19

> I am stumped on this one...
> 
> Any easy way to copy a file from a button event in RB 5.2?  I
> basically want the button to copy DB.rdb to DB.bak.  THis way is
> someone hozes the file, we have a backup.
> 
> Thanks in advance,
> 
> SJ

Maybe I am missing what you are trying to do - but wouldn't
FolderItem.CopyFileTo do what you want?

Jon
0
Jon
5/29/2004 8:45:59 PM
Here's a copy of the code I'm using as a "Backup..." menu item to perform a
simple file copy of the main database. I've made a few assumptions on the
file backup. (1) the backup folder name is in a fixed location with a
fixed name -- it is located as a "child' directory of where the main
database file is located. (2) I assume that the user never wants to
overright a previous backup. To handle this, I created a routine to append
the date as a 6 digit value to the file name, then a sequence number
beginning with one. Thus, if they back up 4 times in one day, they will
have 4 backups with the same date code with a trailing 1, 2, 3, & 4. (3)
The copyto will fail if the file already exists, so I always check for
duplicate files before copying. (4) The copyto command copys the file,
including file name. After copying is done, that is when you rename the
file. If you only want to create a single *.bak file and place it in the
same directory as your live file, then you can extract the necessary
technique for the code below. The only difference is that you will first
have to copy the file to the TEMP directory (first deleting any existing
*.rbd and *.bak files), copy your live file there, rename it, then copy it
back to your working directory.

Oh, and the gcCaution, gdb, gsMsg, gsTitle and gvReturn are all global
properties or constants defined elsewhere.

  Dim rs As RecordSet
  Dim dte As new Date
  Dim strDateString as String, strBackupName as String, strTotalBackups as
String
  Dim nCopy as Integer
  Dim f as FolderItem, nf as FolderItem, bakDir As FolderItem, dataDir As
FolderItem
  Dim dlg as selectFolderDialog 
  
  gsTitle = "Anything you Want"
  gsMsg = "Press OK to backup your database file." + EndOfLine +
EndOfLine
  gsMsg = gsMsg + "Backups are stored in the YourProgramBackup folder
which is " 
  gsMsg = gsMsg + "located in the same folder as the database file." +
EndOfLine
  gvReturn = MsgBox(gsMsg, gcNote+gcOkCancel,gsTitle)
  If gvReturn = 2 Then
    // Cancel
    Exit
  End If

  // Close the database (to prevent in-use conflicts)
  gdb.Close
  
  // Build target string name
  strDateString = Right(str(dte.Year), 2) 
  If len(str(dte.Month)) = 1 Then
    strDateString = strDateString + "0" + str(dte.Month)
  Else
    strDateString = strDateString + str(dte.Month)
  End If
  If len(str(dte.Day)) = 1 Then
    strDateString = strDateString + "0" + str(dte.Day)
  Else
    strDateString = strDateString + str(dte.Day)
  End If
  strDateString = strDateString + "_"
  nCopy = 1
  
  // Locate the DATA directory
  dataDir = GetFolderItem(gdbFile.AbsolutePath).Parent
  // Test to see if backup directory exists
  bakDir = dataDir.Child("YourProgramBackup")
  If bakDir.Exists = False Then
    // Inform User -- directory will be created.
    gsTitle = "Create Backup Directory"
    gsMsg = "YOURPROGRAM will create a folder named 'YourProgramBackup' in
the same folder as the database file." + EndOfLine
    gvReturn = MsgBox (gsMsg,gcCaution,gsTitle)
    bakDir.CreateAsFolder
  End If
  
  If bakDir.Exists = False Then
    // ERROR
    gsTitle = "Error Creating Folder"
    gsMsg = "YOURPROGRAM was unable to create the backup folder." +
EndOfLine + EndOfLine
    gsMsg = gsMsg + "This should not happen. Please try the backup again."
+ EndOfLine
    gvReturn = MsgBox(gsMsg,gcStop,gsTitle)
    Exit
  End If
  
  // Search for unique file name (never overwrite an existing backup)
  Do Until bakDir.Child("YourProgram" + strDateString + str(nCopy) +
".bak").Exists = False
    nCopy = nCopy + 1
  Loop
  strBackupName = "eLog" + strDateString + str(nCopy) + ".bak"
  
  // Copy the file, then rename it
  nf = New folderItem(gdbFile.AbsolutePath)
  nf.CopyFileTo bakDir
  bakDir.Child("YourProgram.rbd").Name = strBackupName
  
  If bakDir.Child(strBackupName).Exists Then
    // Success
    gsTitle = "Backup Complete"
    gsMsg = "You backup has been completed!" + EndOfLine + EndOfLine
    strTotalBackups = str(bakDir.Count + 1)
    #If TargetWin32 Then
      // Windows and Mac report the count number differently (Mac is
ZERO-based)
      strTotalBackups = str(bakDir.Count)
    #EndIF
    gsMsg = gsMsg + "There are now " + strTotalBackups + " backups
stored." + EndOfLine
    gvReturn = MsgBox(gsMsg,gcNote,gsTitle)
  Else
    // Failure
    gsTitle = "Backup Error"
    gsMsg = "Pilot eLog was unable to create a backup." + EndOfLine +
EndOfLine
    gsMsg = gsMsg + "This should not happen. Please try the backup again."
+ EndOfLine
    gvReturn = MsgBox(gsMsg,gcStop,gsTitle)
  End If

0
PubGuy
6/14/2004 1:54:42 PM
Reply:

Similar Artilces:

How to copy a file to a file with a prefixed file name
I'm trying to write a program that will archive selected files to an archive directory. The files in the archive directory will have a prefix in the format yyyymmdd-hhmmss-filename.ext. So, if the file is called "somefile.dat", then the filename in the archive directory should be "20090522-164325-somefile.dat". I'm using Clipper's COPY FILE command to do the copy. I can't figure out how to get the prefix in front of the file name. Creating the prefix string is no problem, but I can't figure out how to tack that onto the front of the filename. If I...

File::Copy::copy With File Handles
The documentation for File::Copy warns against using file handles as arguments: Note that passing in files as handles instead of names may lead to loss of information on some operating systems; it is recommended that you use file names whenever possible. Does this refer to handles created with the older FileHandle module (which is used in the module's synopsis), IO::Handle subclasses, or both? In either case what's the issue with handles that may lead to data loss? Quoth MaggotChild <hsomob1999@yahoo.com>: > The documentation for File::Copy warns agai...

file.exe file generation from file.m file
How to generate application (*.exe) file from *.m file, which has lots of graphics. Program was written for image watermarking by using image processing toolbox. I want to send this program some where else but with out sowing the program codes. By this *.exe no need to use matlab6.5 platform. Also tell me How to generate *.p file from *.m file Which is hide the code to user but for run this program need matlab6.5 Please give me some idea about it. it is very urgent for me. I will be very great full to you "Biswajit Kar" <hibiswajitkar@rediffmail.com> wrote in message ne...

File, Find References, Copy Files: Truncating Long File Names
Hello All- I just experienced this behavior this morning. It was repeatable. Has anyone else seen this? The file Name was cut off after 57 characters. XP Pro SP2 2006 SP0 Office XP 2003 Pro Best Regards, Devon T. Sowell www.3-ddesignsolutions.com How long was the path name in total? Total including the file extension (.SLDASM) = 174. The file Extension was retained, just the Name was chopped off. These are my customer's files. Best Regards, Devon T. Sowell www.3-ddesignsolutions.com "TOP" <kellnerp@cbd.net> wrote in message news:1128364278.638472.150320@f14g2000...

Copy files with a .vbs file
Hi Im a complete newbe at this and would like som help. Im sure this is very easy to do but i dont have any idea as where to start. I would like to have a .vbs file that i can click on to open e message box where I can specify a file. That file should then be copied 5 times and different text should be added infront of the original file name, like this: Org: 12324.txt Result: text1_1234.txt text2_1234.txt text3_1234.txt text4_1234.txt text5_1234.txt Anyone who can help me with this or point me in the right direction? Best regards Daniel -- ------------------------...

Copying a file to another file
Hi, I wrote the following C program to copy a file to another file. #include <stdio.h> #include <stdlib.h> static FILE *open_file ( char *file, char *mode ) { FILE *fp = fopen ( file, mode ); if ( fp == NULL ) { perror ( "Unable to open file" ); exit ( EXIT_FAILURE ); } return fp; } int main ( int argc, char *argv[] ) { /* int ch;*/ FILE *from; FILE *to; char *buffer; long lSize; if ( argc != 3 ) { fprintf ( stderr, "Usage: %s <readfile1> <writefile2>\n", argv[0] ); exit (1);/* E...

http://LongPathTool.com
http://LongPathTool.com - unlock files in-use by other applications + Delete and Copy Path Too Long Files The application solves the problem with inability to copy and delete files and folders with long paths or locked by some application. They could be created by virus/adware/different OS/other software. Normally one can't access such files under Windows and therefore can't delete them either. Please check other Features for more details. Also you can download the latest evaluation version on our download page. Long Path Tool uses a variety of methods to delete the pers...

copy txt file - only copies 1/3 of the file
File.open('oldFile.txt', 'r') do |f1| #file contains XML type data m = f1.gets File.open('newFile.txt','w') do |f2| #newFile to separate data in oldFile f2.puts m.split("<") end end Hello All. There is something that I did that was weird here. I say this because when I open the new file that it creates its 1/3 the size of the original. It seems to just completely cut off. I took off the .split and it still did this, so I know it has nothing to do with split. What do you think is going on? oldFile.txt contains XML formatted data. ...

file extention from file file location
Hi, I am new to perl (only working on this one problem) but I program in other languages. We have an upload script written in cgi. Can anyone tell me how to get the file extension from the variable $File1 (actual file location on uploader's computer) then find out if it is equal to "txt" Thanks in advance for not telling me to read the manual. Ron -- PLEASE NOTE: comp.infosystems.www.authoring.cgi is a SELF-MODERATED newsgroup. aa.net and boutell.com are NOT the originators of the articles and are NOT responsible for their content. HOW TO POST to co...

http://LongPathTool.com
http://LongPathTool.com - copy and delete path too long files Windows tool to copy or delete files and folders with path too long or filename too long error. Just browse to the file and press a button to copy or detele it, thats it! The application solves the problem with inability to copy and delete files and folders with long paths in Explorer. They could be created by virus/adware/Mac OS/other software. Normally one can't access such files under Windows and therefore can't copy or delete them either. Clean up files. Alows to copy and delete files that has path longer the...

Cannot Delete File? Long Path Tool Can - http://CannotDeleteFile.net LONG PATH Tool
Cannot Delete File? Long Path Tool Can - http://CannotDeleteFile.net LONG PATH Tool - Windows tool to copy or delete files and folders with path too long error Windows tool to copy or delete files and folders with path too long or filename too long error. Just browse to the file and press a button to copy or detele it, thats it! The application solves the problem with inability to copy and delete files and folders with long paths in Explorer. They could be created by virus/adware/Mac OS/other software. Normally one can't access such files under Windows and therefore can't ...

java.io.File.getAbsolutePath() vs. java.io.File.getCanonicalPath()
What is the meaning of the term Canonical Path? The API makes it fairly clear does it not? ...https://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#getCanonicalPath()On Mar 5, 3:03 pm, "Sathyaish" <sathya...@gmail.com> wrote:> What is the meaning of the term Canonical Path? Thank you.Sorry, I hadn't scrolled down to the complete definition. Also tried out an example. Sorry for being lazy the first time. I wastrying to save some time. No harm in that.On Mar 5, 3:38 pm, "Sathyaish" <sathya...@gmail.com> wrote:> Also tried out an example. Sorry for b...

Iteration through File.file? misses entries for which File.file?(entry) == true
Hello everyone, I'm new to Ruby, so I'm most likely making an elementary mistake. However, searching Google didn't help me find my answer, and after mucking around with irb I still haven't figured it out. I wrote a method that was intended to take all of the files in a given directory and put them into an array. Here's the code I wrote: def getFiles(dir) pwdFiles = Array.new Dir.foreach(dir) do |entry| pwdFiles.push(entry) if File.file?(entry) == true end end This works fine when called on the working directory --- that is, getFile...

copy all files except dot files
Will the following sequence cd /dest-dir cp /source-dir/* . copy EVERYTHING ? But i don't want those dot files like .profile .sh_history to be copied across. What command to use instead? On 7 Mar 2004 06:28:06 GMT, pui ming Wong <s11976@net2.hkbu.edu.hk> wrote: > Will the following sequence > cd /dest-dir > cp /source-dir/* . > > copy EVERYTHING ? > > But i don't want those dot files like .profile .sh_history > to be copied across. > What command to use instead? > cp /source-dir/* . will not copy dot files. -- Incrsease your earoning pos...

Web resources about - File IO/Copy A File - comp.lang.basic.realbasic

File:Commons-logo.svg - Wikipedia, the free encyclopedia
This image, or parts of it, is an official logo or design used by Wikimedia Foundation or by one of its projects. It is copyrighted by the Wikimedia ...

tar (file format) - Wikipedia, the free encyclopedia
. tar was initially developed to write data to sequential I/O devices for tape backup purposes. It is now commonly used to collect many files ...

The X Files: David Duchovny hated Mulder's wardrobe so much he had reboot doubts
X-Files star David Duchovny admits agent Mulder's sharp suits made him think twice about the reboot.

The Fitz Files: Lisa Wilkinson's fiery interview with Clive Palmer
I note with interest that the fiery interview my Missus, Lisa Wilkinson, did with Clive Palmer on the Today show on Friday morning led the nation's ...

From The Career Files: Change Your Job? Or Change Your Perspective?
The problem with changing jobs in pursuit of happiness is that no job will ever make you happy.

Sessa Capital Files Lawsuit against Ashford Hospitality Prime over Change in Control Provision
Sessa Capital (Master), L.P. (&ldquo;Sessa&rdquo;), owner of 8.2% of the outstanding common shares of Ashford Hospitality Prime, Inc. (NYSE:AHP) ...

California Files Suit Against Southern California Gas Company Over Leak
... the area. Upon investigating, Southern California Gas Company found that, in actuality, the smell was coming from a [&hellip California Files ...

Sports Authority to file Ch 11: Report
Sports Authority is preparing to file for bankruptcy, according to a Bloomberg report.

McDonald’s Customer Files Lawsuit Accusing Chain Of Not Using Real Cheese In Mozzarella Sticks
... the chain over the coals for selling breaded shells filled with fried air instead of mozzarella , another customer in California has filed a ...

Keybase promises frictionless secure file sharing
Keybase, which provided people with a way to encrypt the messages they send, has branched out into file sharing, and it works quite differently ...

Resources last updated: 2/8/2016 4:15:54 AM