Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

wildcard file copying in powerbuilder

660 views
Skip to first unread message

Eric Aling [TeamPS]

unread,
Nov 20, 1997, 3:00:00 AM11/20/97
to

Hi,

I would use the dirlist function to get all the files I want to copy, and
then use the Win32 API FileCopyA() function to copy those file to their
destination.

HTH
--
- Met vriendelijke groet,

Eric Aling [TeamPS], Cypres Informatisering bv, The Netherlands
http://ourworld.compuserve.com/homepages/alingejj


Dan Wolterink <wolt...@dearborn.com> wrote in article
<r9NlB9Q...@forums.powersoft.com>...
> I need to copy a c:\%%*.* to c:\test.txt (as an example). Currently
> I have a batch file that copies this file and i use the powerbuilder
> Run command to run this batch file. But this is not consistent. That is,
if
> two or three windows are open in the application, the run command
doesn't
> run the batch file. Is there any way I can do this?
>
>
>

Roy Kiesler

unread,
Feb 21, 1998, 3:00:00 AM2/21/98
to

Dan/Eric,

The function you want to look at (one function only!) is SHFileOperation().
Here is its PowerBuilder declaration:

FUNCTION long SHFileOperation( REF SHFILEOPSTRUCT lpFileOp ) LIBRARY
"SHELL32.DLL"

You can alternate between SHFileOperation, SHFileOperationA, and
SHFileOperationsW depending if you need unicode or wide-character support
(international apps) - just change the declaration accordingly, or use
aliases. For now, let's stick with simple.

This function copies, moves, renames, or deletes a file system object. It
returns zero if successful, or nonzero otherwise.

It takes a single argument by reference, an SHFILEOPSTRUCT structure. These
are the structure members:

struct SHFILEOPSTRUCT {
long hWnd;
uint wFunc;
string pFrom;
string pTo;
uint fFlags;
boolean bAnyOperationsAborted;
long hNameMappings;
string lpszProgressTitle;
}

Using this function is real simple. Here's an example:

//
// sample code - clicked() event of a command button
//
integer li_rc
SHFILEOPSTRUCT lpFileOp

// supply the function with a handle to the parent window
lpFileOp.hWnd = Handle( Parent )

// determine the desired file operation
// 1 - move, 2 - copy, 3 - delete, 4 - rename
lpFileOp.wFunc = 2

// source file(s) - multiple files should be separated by a NULL. A file
list should be terminated by 2 NULLs. Use of *.* wildcard is acceptable
lpFileOp.pFrom = Space( 256 ) // allocate memory first
lpFileOp.pFrom = "c:\temp\file1.txt"

// to add more file to the previous list use:
// + Char(0) + "c:\temp\file2.txt" + Char(0) + Char(0)

// destination directory
lpFileOp.pTo = Space( 256 )
lpFileOp.pTo = "c:\windows\temp\"

// fFlag can be a combination of any of the following:
// 1 - pTo specifies multiple destination filenames instead of a directory
name.
// 4 - Silent operation. No animated progress dialogs.
// 8 - Give the file being operated on a new name if a file with the
target name already exists.
// 16 - Don't prompt the user for file overwrite confirmation.
// 64 - Allow undo operation.
// 128 - When *.* specified, operate on files only (directories are not
recursed)
// 256 - Don't show filenames in progress dialog
// 512 - Don't prompt the user to confirm directory creation
lpFileOp.fFlags = 8 + 16

// check this flag to see if any previous file operations were aborted by
the user.
lpFileOp.bAnyOperationsAborted = TRUE

// very complex an unnecessary stuff - ignore
lpFileOp.hNameMappings = 0

// the progress dialog title
lpFileOp.lpszProgressTitle = Space( 80 )
lpFileOp.lpszProgressTitle = "Look ma, doing file ops here..."

// Finally, call the damn function...
li_rc = SHFileOperation( lpFileOp )
IF li_rc <> 0 THEN
MessageBox( "Oops!", "An error has occurred during a file operation" )
END IF

//
// end of sample code
//

Hope this helps you.

Roy Kiesler
Software Engineer
Logica Inc.
mailto://kies...@logica.com


0 new messages