|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help me, please view the strange problem!!!My system is Windows XP + SP2, please try the code below, the code will copy all file to another directory. Please create a new directory(C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}), copy some files into directory. //////////////////////////////////////////////////// Invoke the function(the code below successful): If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}\", "c:\test", False, False) <> 0 Then MessageBox.Show("fail") Else MessageBox.Show("done") End If /////////////////////////////////////////////////////// The code below is fail If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}", "c:\test", False, False) <> 0 Then MessageBox.Show("fail") Else MessageBox.Show("done") End If Can anyone tell why????? The class is below ////////////////////////////////////////////////////////////////////////// Public Class FileOperate Private Structure SHFILEOPSTRUCT Dim hWnd As Integer Dim wFunc As Integer Dim pFrom As String Dim pTo As String Dim fFlags As Short Dim fAborted As Boolean Dim hNameMaps As Integer Dim sProgress As String End Structure Private Const FO_DELETE As Short = &H3S Private Const FOF_ALLOWUNDO As Short = &H40S Private Const FOF_NOCONFIRMATION = &H10S Private Const FO_MOVE = &H1S Private Const FO_COPY = &H2S Private Const FOF_NOERRORUI = &H400S Private Const FOF_SILENT = &H4S Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer Private Shared SHFileOp As SHFILEOPSTRUCT Public Shared Function ShellCopy(ByVal SourcePath As String, ByVal DsintedPath As String, Optional ByVal ShowProgress As Boolean = True, _ Optional ByVal CopyEntireDir As Boolean = True) As Int16 If IO.Directory.Exists(DsintedPath) = False Then IO.Directory.CreateDirectory(DsintedPath) Application.DoEvents() If SourcePath.EndsWith("\") Then SourcePath.Remove(SourcePath.Length - 1, 1) If DsintedPath.EndsWith("\") Then DsintedPath.Remove(SourcePath.Length - 1, 1) With SHFileOp .fAborted = True .wFunc = FO_COPY If CopyEntireDir = True Then .pFrom = SourcePath & Chr(0) Else .pFrom = SourcePath & "\*.*" End If .pTo = DsintedPath If ShowProgress = True Then .fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI Else .fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI + FOF_SILENT End If End With Return SHFileOperation(SHFileOp) End Function End Class Look closely at this line:
If DsintedPath.EndsWith("\") Then DsintedPath.Remove(SourcePath.Length - 1, 1) I think it should read: If DsintedPath.EndsWith("\") Then DsintedPath.Remove(DsintedPath.Length - 1, 1) Tony Show quoteHide quote "yxq" wrote: > Hello, > My system is Windows XP + SP2, please try the code below, > the code will copy all file to another directory. > > Please create a new directory(C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}), > copy some files into directory. > > //////////////////////////////////////////////////// > Invoke the function(the code below successful): > > If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}\", > "c:\test", False, False) <> 0 Then > MessageBox.Show("fail") > Else > MessageBox.Show("done") > End If > > /////////////////////////////////////////////////////// > The code below is fail > If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}", > "c:\test", False, False) <> 0 Then > MessageBox.Show("fail") > Else > MessageBox.Show("done") > End If > > Can anyone tell why????? > > > The class is below > ////////////////////////////////////////////////////////////////////////// > Public Class FileOperate > > Private Structure SHFILEOPSTRUCT > Dim hWnd As Integer > Dim wFunc As Integer > Dim pFrom As String > Dim pTo As String > Dim fFlags As Short > Dim fAborted As Boolean > Dim hNameMaps As Integer > Dim sProgress As String > End Structure > > Private Const FO_DELETE As Short = &H3S > Private Const FOF_ALLOWUNDO As Short = &H40S > Private Const FOF_NOCONFIRMATION = &H10S > Private Const FO_MOVE = &H1S > Private Const FO_COPY = &H2S > Private Const FOF_NOERRORUI = &H400S > Private Const FOF_SILENT = &H4S > > Private Declare Function SHFileOperation Lib "shell32.dll" Alias > "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer > > Private Shared SHFileOp As SHFILEOPSTRUCT > > Public Shared Function ShellCopy(ByVal SourcePath As String, ByVal > DsintedPath As String, Optional ByVal ShowProgress As Boolean = True, _ > Optional ByVal CopyEntireDir As Boolean = True) As Int16 > > If IO.Directory.Exists(DsintedPath) = False Then > IO.Directory.CreateDirectory(DsintedPath) > Application.DoEvents() > > If SourcePath.EndsWith("\") Then > SourcePath.Remove(SourcePath.Length - 1, 1) > If DsintedPath.EndsWith("\") Then > DsintedPath.Remove(SourcePath.Length - 1, 1) > > With SHFileOp > .fAborted = True > .wFunc = FO_COPY > > If CopyEntireDir = True Then > .pFrom = SourcePath & Chr(0) > Else > .pFrom = SourcePath & "\*.*" > End If > > .pTo = DsintedPath > > If ShowProgress = True Then > .fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI > Else > .fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI + > FOF_SILENT > End If > > End With > Return SHFileOperation(SHFileOp) > End Function > > End Class > > > > > > Wom, you are right, tony.
But it can not slove my problem, please test the code for me, thank you. If the directory does not contain {91A9BEC9-ED3C-4382-8615-BC0B466D2936}, it will be successful, otherwise, it will be fail. Regards Steven Show quoteHide quote "tlkerns" <tlke***@discussions.microsoft.com> дÈëÏûÏ¢ÐÂÎÅ:397F466D-8015-4EE8-AF79-2D41E9838***@microsoft.com... > Look closely at this line: > > If DsintedPath.EndsWith("\") Then > DsintedPath.Remove(SourcePath.Length - 1, 1) > > I think it should read: > > If DsintedPath.EndsWith("\") Then > DsintedPath.Remove(DsintedPath.Length - 1, 1) > > Tony > > "yxq" wrote: > >> Hello, >> My system is Windows XP + SP2, please try the code below, >> the code will copy all file to another directory. >> >> Please create a new directory(C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}), >> copy some files into directory. >> >> //////////////////////////////////////////////////// >> Invoke the function(the code below successful): >> >> If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}\", >> "c:\test", False, False) <> 0 Then >> MessageBox.Show("fail") >> Else >> MessageBox.Show("done") >> End If >> >> /////////////////////////////////////////////////////// >> The code below is fail >> If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}", >> "c:\test", False, False) <> 0 Then >> MessageBox.Show("fail") >> Else >> MessageBox.Show("done") >> End If >> >> Can anyone tell why????? >> >> >> The class is below >> ////////////////////////////////////////////////////////////////////////// >> Public Class FileOperate >> >> Private Structure SHFILEOPSTRUCT >> Dim hWnd As Integer >> Dim wFunc As Integer >> Dim pFrom As String >> Dim pTo As String >> Dim fFlags As Short >> Dim fAborted As Boolean >> Dim hNameMaps As Integer >> Dim sProgress As String >> End Structure >> >> Private Const FO_DELETE As Short = &H3S >> Private Const FOF_ALLOWUNDO As Short = &H40S >> Private Const FOF_NOCONFIRMATION = &H10S >> Private Const FO_MOVE = &H1S >> Private Const FO_COPY = &H2S >> Private Const FOF_NOERRORUI = &H400S >> Private Const FOF_SILENT = &H4S >> >> Private Declare Function SHFileOperation Lib "shell32.dll" Alias >> "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer >> >> Private Shared SHFileOp As SHFILEOPSTRUCT >> >> Public Shared Function ShellCopy(ByVal SourcePath As String, >> ByVal >> DsintedPath As String, Optional ByVal ShowProgress As Boolean = True, _ >> Optional ByVal CopyEntireDir As Boolean = True) As Int16 >> >> If IO.Directory.Exists(DsintedPath) = False Then >> IO.Directory.CreateDirectory(DsintedPath) >> Application.DoEvents() >> >> If SourcePath.EndsWith("\") Then >> SourcePath.Remove(SourcePath.Length - 1, 1) >> If DsintedPath.EndsWith("\") Then >> DsintedPath.Remove(SourcePath.Length - 1, 1) >> >> With SHFileOp >> .fAborted = True >> .wFunc = FO_COPY >> >> If CopyEntireDir = True Then >> .pFrom = SourcePath & Chr(0) >> Else >> .pFrom = SourcePath & "\*.*" >> End If >> >> .pTo = DsintedPath >> >> If ShowProgress = True Then >> .fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI >> Else >> .fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI + >> FOF_SILENT >> End If >> >> End With >> Return SHFileOperation(SHFileOp) >> End Function >> >> End Class >> >> >> >> >> >>
Compress a string
Bug in VS 2005 VB "Application Framework"? SQL Update - DataViewRow Help needed, Removing duplicate lines in text file How to prevent DISTILLER from propting output filename ? How do I get COMPLETE response from HttpWebResponse using StreamReader??? "Array" of pictureboxes Adding reference errors... my.settings and the connectionstring My form has a hiccup |
|||||||||||||||||||||||