Results 1 to 14 of 14

Thread: moving a file

  1. #1

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    moving a file

    how do i move a file (text document) that the user selects to a designated folder?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. FileCopy "c:\mytext.txt", "c:\my documents\mytext.txt"
    2. Kill "c:\mytext.txt"

  3. #3
    Junior Member
    Join Date
    Mar 2002
    Location
    Belgium
    Posts
    20

    well

    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
    Greets
    Kristof Vandooren

  4. #4

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    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

  5. #5
    Hyperactive Member scsa20's Avatar
    Join Date
    Apr 2001
    Location
    Mars
    Posts
    456
    VB Code:
    1. FileCopy App.Path & "\mytext.txt", "c:\my documents\mytext.txt"
    2. Kill App.Path & "\mytext.txt"

    is that what you wanted??


    p|-|34|2 /\/\3 f0|2 | $p34k 1337
    My TSS quote of the day: "If your haveing a bad day, just press the restart button."

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    "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:
    VB Code:
    1. Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long
    2.  
    3. Private Const MAX_PATH = 260
    4.  
    5. Private Sub Command1_Click()
    6.     Dim tempStr As String, Ret As Long
    7.     'create a buffer string
    8.     tempStr = String(MAX_PATH, 0)
    9.     'returns 1 when successfull, 0 when failed
    10.     Ret = SearchTreeForFile("c:\", "MyExe.exe", tempStr)
    11.     If Ret <> 0 Then
    12.         'use this for your FileCopy command
    13.         MsgBox "Located file at " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
    14.     Else
    15.         MsgBox "File not found!"
    16.     End If
    17. End Sub

  7. #7

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    why cant i just specify a folder to move to, why do i have to give the full path?

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Because your program won't know where the folder is. You have to tell it.

  9. #9

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    i meant just the folder. for example c:\My Documents\ instead of c:\My Documents\myfile.txt

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  11. #11

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    ok thanks anyway

  12. #12

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    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

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Dim sParts() As String
    2. sParts = Split("C:\MyWorld\MyStyle\WhoCares\Junk.txt", "\")
    3.  
    4. 'sParts(UBound(sParts)) contains File name 'Junk.txt'
    5. 'to check
    6. MsgBox sParts(UBound(sParts))

  14. #14

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    thanks for all your help hack. it is appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width