首页  编辑  

用外壳扩展改文件名

Tags: /超级猛料/Stream.File.流、文件和目录/Shell操作/   Date Created:

procedure TForm1.Button1Click(Sender: TObject);

var

 P                 : PWideChar;

 NewPIDL, RenPIDL, PathPIDL: PItemIDList;

 Flags,NumChars    : LongWord;

//Index: Integer;

 NewShellFolder    : IShellFolder;

 Value, PathValue  : string;

begin

 SHGetDesktopFolder(FIDesktopFolder);

 Value := 'hubdog.txt';

 PathValue := 'C:\';

 NumChars := Length(PathValue);

 Flags := 0;

 P := StringToOleStr(PathValue);

 OLECheck(FIDesktopFolder.ParseDisplayName(Application.Handle,nil,P,NumChars,PathPIDL,Flags));

 OLECheck(FIDesktopFolder.BindToObject(PathPIDL,nil,IID_IShellFolder,Pointer(NewShellFolder)));

 NumChars := Length(Value);

 Flags := 0;

 P := StringToOleStr(Value);

 OLECheck(NewShellFolder.ParseDisplayName( Application.Handle,nil,P,NumChars,NewPIDL,Flags));

 if NewShellFolder.SetNameOf(Application.Handle,NewPIDL,StringToOleStr('newhubdog.txt'),128, RenPIDL) = noerror then

   showmessage('ok');

//SHChangeNotify(SHCNE_RENAMEITEM,SHCNF_FLUSH,NewPIDL,nil);

end;