how do i move a file (text document) that the user selects to a designated folder?
Printable View
how do i move a file (text document) that the user selects to a designated folder?
VB Code:
FileCopy "c:\mytext.txt", "c:\my documents\mytext.txt" Kill "c:\mytext.txt"
you can do that with drag drop
code
---------------------------
Private Sub File1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then File1.Drag
End Sub
...
I hope this helps you
great. Is it possible to just say to move it to the same folder as the exe? because i wont always know exactly where it is
VB Code:
FileCopy App.Path & "\mytext.txt", "c:\my documents\mytext.txt" Kill App.Path & "\mytext.txt"
is that what you wanted??
"The same folder as the exe" doesn't mean anything to FileCopy. You will need to know exactly where the file is to be moved.
If you don't know, before the move, then you need to get that path. You can do that, with this::DVB Code:
Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long Private Const MAX_PATH = 260 Private Sub Command1_Click() Dim tempStr As String, Ret As Long 'create a buffer string tempStr = String(MAX_PATH, 0) 'returns 1 when successfull, 0 when failed Ret = SearchTreeForFile("c:\", "MyExe.exe", tempStr) If Ret <> 0 Then 'use this for your FileCopy command MsgBox "Located file at " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1) Else MsgBox "File not found!" End If End Sub
why cant i just specify a folder to move to, why do i have to give the full path?
Because your program won't know where the folder is. You have to tell it.
i meant just the folder. for example c:\My Documents\ instead of c:\My Documents\myfile.txt
Ohh...that because thats what FileCopy is looking for. Full path and file name. If you only specify a path, you will get an error.
Why?
I don't know. It does seem silly, but thats the way it is. :D
ok thanks anyway
well ok then if i have the path:
c:\my documents\myfile.txt
how can i remove the first part and end up with
myfile.txt
VB Code:
Dim sParts() As String sParts = Split("C:\MyWorld\MyStyle\WhoCares\Junk.txt", "\") 'sParts(UBound(sParts)) contains File name 'Junk.txt' 'to check MsgBox sParts(UBound(sParts))
thanks for all your help hack. it is appreciated.