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

SHFileOperation and renaming files

329 views
Skip to first unread message

David Eddy

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

Can the API SHFileOperation be used with FO_RENAME to rename files using
wildcards? Like renaming *.txt to *.doc? If so, does anyone know how this
can be achieved?

Thanks,
David Eddy
noch...@earthlink.net

hi...@btinternet.com

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

Hi Eddy
You can rename files using wildcards as follows:

SHFILEOPSTRUCT FileStruct;
memset(&FileStruct, 0, sizeof(FileStruct));
FileStruct.wFunc = FO_RENAME;
FileStruct.pFrom = "*.txt\0";
FileStruct.pTo = "*.doc\0";
SHFileOperation(&FileStruct);

Hope this helps

Ben Walsh

O'Roukre

unread,
Feb 22, 1998, 3:00:00 AM2/22/98
to David Eddy

There is awesome code at thsi web address:

http://www.planet-source-code.com/vb/

You will find many example of this API call to copy/rename/delete/move files
and folders.

Peter

David Eddy

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

Ben Walsh wrote:
>You can rename files using wildcards as follows:
>
>SHFILEOPSTRUCT FileStruct;
>memset(&FileStruct, 0, sizeof(FileStruct));
>FileStruct.wFunc = FO_RENAME;
>FileStruct.pFrom = "*.txt\0";
>FileStruct.pTo = "*.doc\0";
>SHFileOperation(&FileStruct);


Hello,
Does this code really work for you? When I try and implement it like this I
get a Window's error that says:
"Cannot create or replace *. Cannot find the specified file... Make sure you
specify the correct path and filename"

Any ideas why?

David


hi...@btinternet.com wrote in message <34EEABEC...@btinternet.com>...


>Hi Eddy
>You can rename files using wildcards as follows:
>
>SHFILEOPSTRUCT FileStruct;
>memset(&FileStruct, 0, sizeof(FileStruct));
>FileStruct.wFunc = FO_RENAME;
>FileStruct.pFrom = "*.txt\0";
>FileStruct.pTo = "*.doc\0";
>SHFileOperation(&FileStruct);
>
>Hope this helps
>
>Ben Walsh
>

Jyrki H

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

Try using this function (Ret = BinRename("c:\temp\*.TXT","c:\temp\*.doc") )
:

Public Const FO_RENAME = &H4
Public Const FOF_FILESONLY = &H80 ' on *.*, do only files
Public Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.

Public Function BinReName(FromFileName As String, ToFileName As String) As
Boolean
Dim FileOperation As SHFILEOPSTRUCT
Dim lReturn As Long
On Error Resume Next
With FileOperation
.wFunc = FO_RENAME
.pFrom = FName
.pTo = TName
.fFlags = FOF_NOCONFIRMATION Or FOF_FILESONLY
End With
lReturn = SHFileOperation(FileOperation)
BinReName = (lReturn = 0)
End Function

Hope this works for you.

Jyrki H.
jyrki.ha...@ids.fi

David Eddy wrote in message <6ckl7d$f...@chile.earthlink.net>...

Michael Urban

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

Jyrki H wrote:
>
> Try using this function (Ret = BinRename("c:\temp\*.TXT","c:\temp\*.doc") )
> :
>
> Public Const FO_RENAME = &H4
> Public Const FOF_FILESONLY = &H80 ' on *.*, do only files
> Public Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.
>
> Public Function BinReName(FromFileName As String, ToFileName As String) As
> Boolean
> Dim FileOperation As SHFILEOPSTRUCT
> Dim lReturn As Long
> On Error Resume Next
> With FileOperation
> .wFunc = FO_RENAME
> .pFrom = FName
> .pTo = TName
> .fFlags = FOF_NOCONFIRMATION Or FOF_FILESONLY
> End With
> lReturn = SHFileOperation(FileOperation)
> BinReName = (lReturn = 0)
> End Function
>
> Hope this works for you.
>
> Jyrki H.
> jyrki.ha...@ids.fi
>
>

I tried using this function in my code, and got the following error:

Can't find DLL entry point SHFileOperationA in shell32.dll

I have seen this error before, but can't remember how to fix it. I am
calling other shell32.dll functions in my program without error. I
pasted the declare, type and contants from the VB5 API viewer. Does
anyone recognize this, and know what the solution is?

I'm using Win95B (OSR2) if that makes any difference.

--
Michael R. Urban
Lead Meteorologist
National Weather Service, WFO Wichita, Kansas
ur...@sac.ict.noaa.gov

hi...@btinternet.com

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

Why are you posting VB code ?

Jyrki H wrote:

> Try using this function (Ret = BinRename("c:\temp\*.TXT","c:\temp\*.doc") )
> :
>
> Public Const FO_RENAME = &H4
> Public Const FOF_FILESONLY = &H80 ' on *.*, do only files
> Public Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.
>
> Public Function BinReName(FromFileName As String, ToFileName As String) As
> Boolean
> Dim FileOperation As SHFILEOPSTRUCT
> Dim lReturn As Long
> On Error Resume Next
> With FileOperation
> .wFunc = FO_RENAME
> .pFrom = FName
> .pTo = TName
> .fFlags = FOF_NOCONFIRMATION Or FOF_FILESONLY
> End With
> lReturn = SHFileOperation(FileOperation)
> BinReName = (lReturn = 0)
> End Function
>
> Hope this works for you.
>
> Jyrki H.
> jyrki.ha...@ids.fi
>

Stephen Goneau

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

I remember this one, it is so trivial and terribly annoying. When I had it
there was a space in front of one of the pieces of the declares statement
that was inside of quotes.

Something likes this (just an example)
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "
RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal
lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Try deleting the space and see what happens.

Stephen Goneau

Michael Urban wrote in message <34F3B6...@sac.ict.noaa.gov>...

Jyrki H

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

Please look at the newsgroup names the original issue was posted to.

Jyrki.

hi...@btinternet.com wrote in message <34F3F8AD...@btinternet.com>...

0 new messages