The VB. 我使用的净功能
<DllImport("shell32.dll")>
Private Function SHGetKnownFolderPath _
(<MarshalAs(UnmanagedType.LPStruct)> ByVal rfid As Guid _
, ByVal dwFlags As UInt32 _
, ByVal hToken As IntPtr _
, ByRef pszPath As IntPtr
) As Int32
End Function
Public Function GetDownloadsFolder() As String
Dim Result As String = ""
Dim ppszPath As IntPtr
Dim gGuid As Guid = New Guid("{374DE290-123F-4565-9164-39C4925E467B}")
If SHGetKnownFolderPath(gGuid, 0, 0, ppszPath) = 0 Then
Result = Marshal.PtrToStringUni(ppszPath)
Marshal.FreeCoTaskMem(ppszPath)
End If
as recommended by Ray (see comments below)
Marshal.FreeCoTaskMem(ppszPath)
Return Result
End Function
在我的节目中,我呼吁它把一些CSV档案转移到另一个文件夹中。
Dim sDownloadFolder = GetDownloadsFolder()
Dim di = New DirectoryInfo(sDownloadFolder)
Move all CSV files that begin with BE in specific folder
that has been defined in a CONFIG file (variable: sExtractPath
For Each fi As FileInfo In di.GetFiles("BE*.csv")
Dim sFilename = sExtractPath & "" & fi.Name
File.Move(fi.FullName, sFilename)
Next