怎么修改一个目录的目录名?(100分)

  • 主题发起人 主题发起人 DreamTiger
  • 开始时间 开始时间
D

DreamTiger

Unregistered / Unconfirmed
GUEST, unregistred user!
根据SysTree控件中TSysTreeView的Reset函数,写了下面的函<br>数,但总是出错!<br><br>function ChangeDirectoryName(OldDirectoryName: string;NewDirectoryName:string): boolean;<br>var<br>&nbsp; RootFolder: IShellFolder;<br>&nbsp; RootID: PItemIDList;<br>&nbsp; OutID: PItemIDList;<br>&nbsp; iResult: HRESULT;<br><br>&nbsp; OLEStr: array[0..MAX_PATH] of WideChar;<br>&nbsp; Eaten: ULONG;<br>&nbsp; Attr: ULONG;<br>begin<br>&nbsp; OLECheck(SHGetDesktopFolder(RootFolder));<br>&nbsp; try<br>&nbsp; &nbsp; OLECheck(RootFolder.ParseDisplayName(0, NIL,<br>&nbsp; &nbsp; &nbsp; &nbsp;StringToWideChar(OldDirectoryName, OLEStr, MAX_PATH), Eaten, RootID, Attr));//这句出错,什么无法指明的错误,晕倒<br>&nbsp; &nbsp; iResult := RootFolder.SetNameOf(0,RootID,PWideChar(NewDirectoryName),SHGDN_NORMAL,OutID);<br>&nbsp; &nbsp; result := iResult = NOERROR;<br>&nbsp; except<br>&nbsp; &nbsp; result := false;<br>&nbsp; end;<br>end;<br><br>哪位大侠出手?
 
如果你是想改文件名的话,试试我这个<br>把c:/hubdog.txt 改成c:/newhubdog.txt<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; P: PWideChar;<br>&nbsp; NewPIDL,RenPIDL,PathPIDL: PItemIDList;<br>&nbsp; Flags,<br>&nbsp; NumChars: LongWord;<br>&nbsp; //Index: Integer;<br>&nbsp; NewShellFolder: IShellFolder;<br>&nbsp; Value,PathValue:String;<br>begin<br>&nbsp; SHGetDesktopFolder(FIDesktopFolder);<br>&nbsp; Value:='hubdog.txt';<br>&nbsp; PathValue:='C:/';<br>&nbsp; NumChars := Length(PathValue);<br>&nbsp; Flags := 0;<br>&nbsp; P := StringToOleStr(PathValue);<br><br>&nbsp; OLECheck(<br>&nbsp; &nbsp; FIDesktopFolder.ParseDisplayName(<br>&nbsp; &nbsp; &nbsp; Application.Handle,<br>&nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; P,<br>&nbsp; &nbsp; &nbsp; NumChars,<br>&nbsp; &nbsp; &nbsp; PathPIDL,<br>&nbsp; &nbsp; &nbsp; Flags)<br>&nbsp; &nbsp;);<br><br>&nbsp; OLECheck(<br>&nbsp; &nbsp; FIDesktopFolder.BindToObject(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PathPIDL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IID_IShellFolder,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(NewShellFolder))<br>&nbsp; &nbsp;);<br><br>&nbsp; NumChars := Length(Value);<br>&nbsp; Flags := 0;<br>&nbsp; P := StringToOleStr(Value);<br><br>&nbsp; OLECheck(<br>&nbsp; &nbsp; NewShellFolder.ParseDisplayName(<br>&nbsp; &nbsp; &nbsp; Application.Handle,<br>&nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; P,<br>&nbsp; &nbsp; &nbsp; NumChars,<br>&nbsp; &nbsp; &nbsp; NewPIDL,<br>&nbsp; &nbsp; &nbsp; Flags)<br>&nbsp; &nbsp;);<br><br>&nbsp; if NewShellFolder.SetNameOf(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.Handle,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NewPIDL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StringToOleStr('newhubdog.txt'),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 128,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RenPIDL<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )=noerror then<br>&nbsp; &nbsp; showmessage('ok');<br>&nbsp; //SHChangeNotify(SHCNE_RENAMEITEM,SHCNF_FLUSH,NewPIDL,nil);<br>end;
 
呵呵,这个问题我在exex上骗了别人800分
 
//开始你怎么把问题删啦。<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; F:TShFileOpStruct;<br>begin<br>&nbsp; F.wnd:=Handle;<br>&nbsp; F.wFunc:=FO_MOVE; {操作方式}<br>&nbsp; F.pFrom:=PChar('c:/test'+#0#0);<br>&nbsp; F.pTo:=PChar('c:/test2'+#0#0);<br>&nbsp; F.fFlags:=FOF_ALLOWUNDO OR FOF_RENAMEONCOLLISION;<br>&nbsp; ShFileOperation(F);<br>end;
 
hehe,前卫我想他问的是用ishellfolder的用法吧<br>
 
hehe.他第一个(已删除)问题说使用ShFileOperation不行....
 
呵呵 ,我比你还简单<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; RenameFile('c:/temp','c:/temp1');<br>end;
 
不错,你的简单。呵呵。都怪DreamTiger,(^o^) 他说不行,我就当真.....
 
都是我的错,输入参数弄错了,呜呜。<br>RenameFile和ShFileOperation我都试过,以为不行,没想到...<br><br>hubdog:你的例子是修改文件的,能否用来修改目录呢?<br><br>沈前卫:当时我看了Systree的例子,以为能搞定了,所以... <br>
 
我例子什么都能改,包括我的电脑都能改成hubdog head<br>rename只能改目录,好象不能改特殊的shellfolder
 
多人接受答案了。
 
后退
顶部