Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SHFileOperation

Posted on 1999-06-30
6
Medium Priority
?
264 Views
Last Modified: 2013-12-03
This function works on Windows 95 but not on Windows NT. It returns error (1026).

Can somebody help me ?
0
Comment
Question by:kctan100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 15

Expert Comment

by:simonet
ID: 1401839
What's you Windows NT version ?

Alex
0
 

Author Comment

by:kctan100
ID: 1401840
NT 4.0 (option pack 5).
0
 
LVL 4

Expert Comment

by:Radler
ID: 1401841
Post your code, please.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 32

Expert Comment

by:jhance
ID: 1401842
SHFileOperation does work on NT.  I suspect you're doing something wrong that just happens to work OK on Win95.

Post the code that is going wrong.
0
 

Author Comment

by:kctan100
ID: 1401843
I manage to solve the problem. Thank you very much!
0
 
LVL 4

Accepted Solution

by:
Radler earned 20 total points
ID: 1401844
I have code using it at Windows NT and work fine, except by the error code sended  when the user click at "Cancel" button.
See:
uses Windows, Classes, ShellAPI;

const
      FOF_DEFAULT_IDEAL    = FOF_MULTIDESTFILES + FOF_RENAMEONCOLLISION + FOF_NOCONFIRMATION + FOF_ALLOWUNDO +
                                       FOF_FILESONLY + FOF_NOCONFIRMMKDIR + FOF_NOERRORUI + FOF_SIMPLEPROGRESS;
      FOF_DEFAULT_DELTREE  = FOF_NOCONFIRMATION + FOF_ALLOWUNDO + FOF_NOERRORUI;
      FOF_DEFAULT_COPY     = FOF_NOCONFIRMATION + FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR + FOF_NOERRORUI + FOF_MULTIDESTFILES;
      FOF_DEFAULT_DELFILES = FOF_DEFAULT_DELTREE;

{---------------------------------------------------------------------------------------------}
{Copia todos os arquivos de uma pasta para outra}
function ShellCopyDir( hWnd : THandle ; const Source, Dest : string; Flags : FILEOP_FLAGS; WinTitle : PChar ) : integer;
var
  FileOpShell : TSHFileOpStruct;
  Src, Dst : array[0..1024] of char;
  OldDir : string;
begin
      if WinTitle <> nil then begin
            Flags:=Flags + FOF_SIMPLEPROGRESS;
      end;
      if not DirectoryExists( Dest ) then begin
            ForceDirectories( Dest );
            if not DirectoryExists( Dest ) then begin
                  Result:=ERROR_CANNOT_MAKE;
                  Exit;
            end;
      end;
      StrPCopy( Src, Source + '\*.*' );
      StrPCopy( Dst, Dest );
      with FileOpShell do begin
            wFunc:=FO_COPY;
            pFrom:=Src;
            pTo:=Dst;
            fFlags:=Flags;
            lpszProgressTitle:=WinTitle;
            Wnd:=hWnd;
            hNameMappings:=nil;
            fAnyOperationsAborted:=False;
      end;
      OldDir:=GetCurrentDir;
      ChDir( Dest );
      Result:=ShFileOperation( FileOpShell );
      if FileOpShell.fAnyOperationsAborted then begin
            Result:=ERROR_CANCELLED;
      end;
      ChDir( OldDir );
end;
{---------------------------------------------------------------------------------------------}
{Apaga arquivos/Diretorios atraves do shell do windows}
function ShellDeleteFiles( hWnd : THandle ; const DirName : string; Flags : FILEOP_FLAGS; WinTitle : PChar ) : integer;
var
  FileOpShell : TSHFileOpStruct;
  Oper : array[0..1024] of char;
begin
      if WinTitle <> nil then begin
            Flags:=Flags + FOF_SIMPLEPROGRESS;
      end;
      with FileOpShell do begin
            wFunc:=FO_DELETE;
            pFrom:=Oper;
            pTo:=Oper; //pra garantir a rapadura!
            fFlags:=Flags;
            lpszProgressTitle:=WinTitle;
            Wnd:=hWnd;
            hNameMappings:=nil;
            fAnyOperationsAborted:=False;
      end;
      StrPCopy( Oper, DirName );
      StrCat(Oper, PChar( ExtractFileName( FindFirstChildFile( DirName )) ) );
      Result:=0;
      try
            while Oper <> EmptyStr do begin
                  Result:=ShFileOperation( FileOpShell );
                  if FileOpShell.fAnyOperationsAborted then begin
                        Result:=ERROR_REQUEST_ABORTED;
                        break;
                  end else begin
                        if Result <> 0 then begin
                              Break;
                        end;
                  end;
                  StrPCopy(Oper, FindFirstChildFile( DirName ) );
            end;
      except
            Result:=ERROR_EXCEPTION_IN_SERVICE;
      end;
end;

{---------------------------------------------------------------------------------------------}
{Apaga arquivos/Diretorios atraves do shell do windows}
function ShellDelTree( hWnd : THandle ; const Name : string; Flags : FILEOP_FLAGS; WinTitle : PChar ) : boolean;
var
  FileOpShell : TSHFileOpStruct;
  Oper : array[0..1024] of char;
begin
      if WinTitle <> nil then begin
            Flags:=Flags + FOF_SIMPLEPROGRESS;
      end;
      StrPCopy(Oper, Name + '\*'); //Sem esta mascara sempre da pau!!!!!!!!
      with FileOpShell do begin
            wFunc:=FO_DELETE;
            pFrom:=Oper;
            pTo:=Oper; //pra garantir a rapadura!
            fFlags:=Flags;
            lpszProgressTitle:=WinTitle;
            Wnd:=hWnd;
            hNameMappings:=nil;
      end;
      ShFileOperation( FileOpShell );
      if (StrCountRepet('\', Name ) >= 4) then begin
            //Raiz de unidade de rede(Ver caso netware}
            Result:=RemoveDir( Name );
      end else begin
            if ISUNCName( Name ) then begin
                  Result:=True;
            end else begin
                  if (StrCountRepet('\', Name ) = 1) and (System.Pos('.', Name ) <> 0) then begin
                        Result:=True;
                  end else begin
                        Result:=RemoveDir( Name );
                  end;
            end;
      end;
end;


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question