Copying files from one folder to another folder in MapBasic

592 views
Skip to first unread message

Brad

unread,
Feb 24, 2012, 4:31:23 PM2/24/12
to mapi...@googlegroups.com
I've been looking through several threads but can't find anything that deals directly with this topic.  Is there a way to move files from one folder to another folder (new folder is set by a variable) in MapBasic.  I tried something with a Windows API but I really have no clue when it comes to Windows API.  Can anyone help?

Thanks!

Brad
GeoSpatial Analyst, Supervalu

Bo Victor Thomsen

unread,
Feb 24, 2012, 6:22:40 PM2/24/12
to mapi...@googlegroups.com
You can use the following snippets:

+++++++++++++++++++++++++++++++++++++++++++++++++
Declare Function CopyFile Lib "kernel32" Alias "CopyFileA"
(ByVal lpExistingFileName As String,
ByVal lpNewFileName As String,
ByVal bFailIfExists As Integer) As Integer

Declare Function MoveFile Lib "kernel32" Alias "MoveFileA"
(byval lpExistingFileName as string,
byval lpNewFileName as string) as Integer

Declare Sub Main
Sub Main

Dim nRet as integer, file_from as string, file_to as string

file_from = "filea.txt"
file_to= "fileb.txt"
nRet = CopyFile (file_from,file_to,1)
nRet = MoveFile (file_from,file_to)

End Sub

.
+++++++++++++++++++++++++++++++++++++++++++++++++
Not tested though..

Regards
Bo Victor Thomsen
Aestas-GIS
Denmark

> --
> You received this message because you are subscribed to the
> Google Groups "MapInfo-L" group.To post a message to this group, send
> email to mapi...@googlegroups.com
> To unsubscribe from this group, go to:
> http://groups.google.com/group/mapinfo-l/subscribe?hl=en
> For more options, information and links to MapInfo resources (searching
> archives, feature requests, to visit our Wiki, visit the Welcome page at
> http://groups.google.com/group/mapinfo-l?hl=en

Martin Hodder

unread,
Feb 25, 2012, 6:11:25 AM2/25/12
to mapi...@googlegroups.com

Hi Brad,

 

Have you tried the Save File command in Mapbasic?

 

Syntax

 

Save File old_filespec As new_filespec [ Append ] 

old_filespec is a string representing the name (and, optionally, the path) of an existing file; the file must not be open.

 

new_filespec is a string representing the name (and, optionally, the path) to which the file will be copied; the file must not be open.

 

Description

The Save File statement copies a file. The file must not already be open for input/output.

 

If you include the optional Append keyword, and if the file new_filespec already exists, the contents of the file old_filespec are appended to the end of the file new_filespec.

 

Do not use Save File to copy a file that is a component of an open table (for example, filename.tab, filename.map, etc.). To copy a table, use the Commit Table...As statement.

 

The Save File statement cannot copy a file to itself.

 

Example

Save File "settings.txt" As "settings.bak"

 

 

 

Sems like that might work?

 

 

 

 

Regards

Martin Hodder
Higher Mapping Solutions
www.highermappingsolutions.com

--

Mustafa OZCETiN

unread,
Feb 26, 2012, 3:30:23 AM2/26/12
to MapInfo-L
Hi Brad,

As a general rule, you may consider writing a reusable Win32 DLL that
wraps common IO operations like copy, move, delete etc. This may be
convenient and reusable for other prejects too.

Mustafa
Reply all
Reply to author
Forward
0 new messages