[Gambas-user] COPY file if "file allready exist"

Willy Raets willy at ...2734...
Wed Feb 8 22:30:52 CET 2012


Example:
File: CopyMe.txt
Location: Userhome directory/MyFiles
Copy to: Userhome directory/MyCopyFiles 

  DIM sSourcePath, sCopyPath AS String
  sSourcePath = User.Home & "/MyFiles"
  sCopyPath = User.Home & "/MyCopyFiles"
  'First check if file exists
  If Exist(sSourcePath & "/CopyMe.txt") THEN 
   'Now check if copyto directory exists
    IF NOT (Exist(sCopyPath)) THEN 
      MKDIR sCopyPath
    ENDIF 
   'Now check if file exists
    IF NOT (Exist(sCopyPath & "/CopyMe.txt")) THEN 
      COPY sSourcePath & "CopyMe.txt" TO sCopyPath & "/CopyMe.txt"
    ELSE 
      'If Exists first remove old file then copy new file
      KILL sCopyPath & "/CopyMe.txt"
      COPY sSourcePath & "CopyMe.txt" TO sCopyPath & "/CopyMe.txt"
    ENDIF 
  ENDIF 

This will only generate errors in case you have not enough access rights
on the directory.

Hope this helps...

Willy

On wo, 2012-02-08 at 13:14 -0800, abbat wrote:
> Sorry, if it's abasic question (but GAMBAS is Almost mean BASIC :-))
> 
> How to copy a file if it is already exist?
> And do not get any error.
> Overwrite
> 
> Tnx.

-- 
Met vriendelijke groeten/ With kind regards,

Willy Raets,
Voorzitter/chairman,
Earthship Belgium vzw.

Nederlandse website: http://www.earthshipbelgium.be/nl.html
English Website: http://www.earthshipbelgium.be/en.html





More information about the User mailing list