Results 1 to 19 of 19

Thread: copy a created file to another location.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    copy a created file to another location.

    Hi all,

    I am still playing with an little app that creates an xml file and a text file. is there a simple way to get the created file to another location. The file is bieng created in C:\PROGRAM FILES\Image text Editor\photos\ but when its wrtten I need to get it to here C:\PROGRAM FILES\Image text Editor\ .I have included the code bieng used anybody got any ideas.

    thanks in advance
    R

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.  
    4.     Dim f1 As Integer, jpgurl As String, MyPath As String, Artist As String, xmlpath As String, songpath As String, slidenode As String, songname As String, mp3path As String, f2 As Integer, i As Integer
    5.     Dim myFolder As String, mytext As String
    6.  
    7.     myFolder = "photos/"
    8.     mytext = "your image Description here"
    9.  
    10.    
    11.     mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
    12.     xmlpath = "C:\PROGRAM FILES\Image text Editor\"
    13.    
    14.          f2 = FreeFile
    15.     Open mp3path & "jpg.txt" For Output As #f2       ' if you don't need mp3.txt take out
    16.      f1 = FreeFile
    17.      
    18.     Open xmlpath & "album.xml" For Output As #f1
    19.     Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
    20.     Print #f1, "<slides>"
    21.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    22.     i = 1
    23.     While Not Len(songname) = 0
    24.         'Print #f1, "<photo>"
    25.  
    26.         Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
    27. Print #f2, songname
    28.         Sleep 100                                ' slight pause, needed
    29.         songname = Dir                           ' get next image
    30.  
    31.         'Print #f1, "</photo>"
    32.    
    33.     Wend
    34.     Print #f1, "</slides>"
    35.    
    36.  
    37.    
    38.    Close

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: copy a created file to another location.

    either change the path in out open/output or

    use FileCopy() to copy it after u are done writing it...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: copy a created file to another location.

    Therefore, do you want two instances of the File (the orig, and a copy)?
    If so, then use FileCopy().

    Also, you have Opened two files but Close only one.....
    (Inlude Close f1, and Close f2)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: copy a created file to another location.

    Quote Originally Posted by Bruce Fox
    Therefore, do you want two instances of the File (the orig, and a copy)?
    If so, then use FileCopy().

    Also, you have Opened two files but Close only one.....
    (Inlude Close f1, and Close f2)
    yes 2 copies is wht I was trying to get it to do in the firstplace but if I set the path which I hve called mp3 path from a similar thing I was doing the text file is empty so Im not sure how to do it

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: copy a created file to another location.

    I have tried using file copy using this code but I get the error saying the file is already open and Im not sure how to close it any ideas

    thanks
    R

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.  
    4.     Dim f1 As Integer, jpgurl As String, MyPath As String, Artist As String, xmlpath As String, songpath As String, slidenode As String, songname As String, mp3path As String, f2 As Integer, i As Integer
    5.     Dim myFolder As String, mytext As String
    6.  
    7.     myFolder = "photos/"
    8.     mytext = "your image Description here"
    9.  
    10.    
    11.     mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
    12.     xmlpath = "C:\PROGRAM FILES\Image text Editor\"
    13.    
    14.          f2 = FreeFile
    15.     Open mp3path & "jpg.txt" For Output As #f2       ' if you don't need mp3.txt take out
    16.      f1 = FreeFile
    17.      
    18.     Open xmlpath & "album.xml" For Output As #f1
    19.     Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
    20.     Print #f1, "<slides>"
    21.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    22.     i = 1
    23.     While Not Len(songname) = 0
    24.         'Print #f1, "<photo>"
    25.  
    26.         Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
    27. Print #f2, songname
    28.         Sleep 100                                ' slight pause, needed
    29.         songname = Dir                           ' get next track
    30.  
    31.         'Print #f1, "</photo>"
    32.    
    33.     Wend
    34.     Print #f1, "</slides>"
    35.     FileCopy "C:\PROGRAM FILES\Image text Editor\photos\jpg.txt", "C:\PROGRAM FILES\Image text Editor\"
    36.  
    37.    
    38.    
    39. Close
    40. End Sub

  6. #6

  7. #7

  8. #8
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: copy a created file to another location.

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.     Dim myFolder As String, mytext As String
    4.     Dim mp3path As String, xmlpath As String
    5.     Dim songname As String, i As Integer
    6.     Dim f1 As Integer, f2 As Integer
    7.    
    8.     '/// Dim jpgurl As String, MyPath As String, Artist As String, songpath As String, slidenode As String
    9.    
    10.     myFolder = "photos/"
    11.     mytext = "your image Description here"
    12.  
    13.     mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
    14.     xmlpath = "C:\PROGRAM FILES\Image text Editor\"
    15.    
    16.     f1 = FreeFile
    17.     f2 = FreeFile
    18.    
    19.     Open mp3path & "jpg.txt" For Output As #f2       ' if you don't need mp3.txt take out
    20.     Open xmlpath & "album.xml" For Output As #f1
    21.    
    22.     Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
    23.     Print #f1, "<slides>"
    24.    
    25.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    26.     i = 1
    27.    
    28.     While Not Len(songname) = 0
    29.         'Print #f1, "<photo>"
    30.         Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
    31.         Print #f2, songname
    32.         Sleep 100                                ' slight pause, needed
    33.         songname = Dir                           ' get next track
    34.         'Print #f1, "</photo>"
    35.     Wend
    36.    
    37.     Print #f1, "</slides>"
    38.    
    39.     Close #f1
    40.     Close #f2
    41.    
    42.     FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
    43.  
    44. End Sub

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: copy a created file to another location.

    Thanks for the nicely formatted code thats what I need to learn to do before posting. I am still getting an error saying the files is still open and when I select debug its highlighting this line

    VB Code:
    1. Open xmlpath & "album.xml" For Output As #f1

    but I thought that was bieng closed.

    any other uggestions

    Quote Originally Posted by rory
    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.     Dim myFolder As String, mytext As String
    4.     Dim mp3path As String, xmlpath As String
    5.     Dim songname As String, i As Integer
    6.     Dim f1 As Integer, f2 As Integer
    7.    
    8.     '/// Dim jpgurl As String, MyPath As String, Artist As String, songpath As String, slidenode As String
    9.    
    10.     myFolder = "photos/"
    11.     mytext = "your image Description here"
    12.  
    13.     mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
    14.     xmlpath = "C:\PROGRAM FILES\Image text Editor\"
    15.    
    16.     f1 = FreeFile
    17.     f2 = FreeFile
    18.    
    19.     Open mp3path & "jpg.txt" For Output As #f2       ' if you don't need mp3.txt take out
    20.     Open xmlpath & "album.xml" For Output As #f1
    21.    
    22.     Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
    23.     Print #f1, "<slides>"
    24.    
    25.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    26.     i = 1
    27.    
    28.     While Not Len(songname) = 0
    29.         'Print #f1, "<photo>"
    30.         Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
    31.         Print #f2, songname
    32.         Sleep 100                                ' slight pause, needed
    33.         songname = Dir                           ' get next track
    34.         'Print #f1, "</photo>"
    35.     Wend
    36.    
    37.     Print #f1, "</slides>"
    38.    
    39.     Close #f1
    40.     Close #f2
    41.    
    42.     FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
    43.  
    44. End Sub

  10. #10
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: copy a created file to another location.

    Maybe try this ..

    Open xmlpath & "album.xml" For Output As #f1
    Open mp3path & "jpg.txt" For Output As #f2

    Also, is it possible the file is opened in another program or browser?

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: copy a created file to another location.

    End your program. Then try to manually delete the file? If you can delete it what happens when you run the program again? BTW, what does the code you use to end the program look like?

  12. #12
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: copy a created file to another location.

    you have the freefile numbers together

    f1 = FreeFile
    f2 = FreeFile

    they will be getting the same number, try splitting them back up like in your first post.

    casey.

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: copy a created file to another location.

    Quote Originally Posted by vbasicgirl
    you have the freefile numbers together

    f1 = FreeFile
    f2 = FreeFile

    they will be getting the same number, try splitting them back up like in your first post.

    casey.
    You're right!

  14. #14
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: copy a created file to another location.

    Quote Originally Posted by vbasicgirl
    you have the freefile numbers together

    f1 = FreeFile
    f2 = FreeFile

    they will be getting the same number, try splitting them back up like in your first post.

    casey.
    Hmmmm, so much for being neat ..
    Thanks, i'll know that now ..

    so basically it would be like this ..

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.     Dim myFolder As String, mytext As String
    4.     Dim mp3path As String, xmlpath As String
    5.     Dim songname As String, i As Integer
    6.     Dim f1 As Integer, f2 As Integer
    7.    
    8.     myFolder = "photos/"
    9.     mytext = "your image Description here"
    10.  
    11.     mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
    12.     xmlpath = "C:\PROGRAM FILES\Image text Editor\"
    13.    
    14.     f1 = FreeFile
    15.     Open xmlpath & "album.xml" For Output As #f1
    16.    
    17.     f2 = FreeFile
    18.     Open mp3path & "jpg.txt" For Output As #f2
    19.    
    20.     Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
    21.     Print #f1, "<slides>"
    22.    
    23.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    24.     i = 1
    25.    
    26.     While Not Len(songname) = 0
    27.         'Print #f1, "<photo>"
    28.         Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
    29.         Print #f2, songname
    30.         Sleep 100                        ' slight pause, needed
    31.         songname = Dir                   ' get next track
    32.         'Print #f1, "</photo>"
    33.     Wend
    34.    
    35.     Print #f1, "</slides>"
    36.    
    37.     Close #f1
    38.     Close #f2
    39.    
    40.     FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
    41.  
    42. End Sub
    Last edited by rory; Jun 22nd, 2006 at 04:30 AM.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: copy a created file to another location.

    thanks for the replies, I have tried ammending my code to this as outlined in one of the posts but the files are still not bieng copied any other suggestions?

    thanks R

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.     Dim myFolder As String, mytext As String
    4.     Dim mp3path As String, xmlpath As String
    5.     Dim songname As String, i As Integer
    6.     Dim f1 As Integer, f2 As Integer
    7.    
    8.     myFolder = "photos/"
    9.     mytext = "your image Description here"
    10.  
    11.     mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
    12.     xmlpath = "C:\PROGRAM FILES\Image text Editor\"
    13.    
    14.     f1 = FreeFile
    15.     Open xmlpath & "album.xml" For Output As #f1
    16.    
    17.     f2 = FreeFile
    18.     Open mp3path & "jpg.txt" For Output As #f2
    19.    
    20.     Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
    21.     Print #f1, "<slides>"
    22.    
    23.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    24.     i = 1
    25.    
    26.     While Not Len(songname) = 0
    27.         'Print #f1, "<photo>"
    28.         Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
    29.         Print #f2, songname
    30.         Sleep 100                        ' slight pause, needed
    31.         songname = Dir                   ' get next track
    32.         'Print #f1, "</photo>"
    33.     Wend
    34.    
    35.     Print #f1, "</slides>"
    36.    
    37.     Close #f1
    38.     Close #f2
    39.    
    40.     FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
    41.  
    42. End Sub

  16. #16
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: copy a created file to another location.

    VB Code:
    1. Close #f1
    2.     Close #f2
    3.    
    4.     FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
    xmlpath & "album.xml" already exists at this point, doesn't it? So you're overwriting album.xml with jpg.txt? So why create album.xml in the first place?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: copy a created file to another location.

    ah yes I see so I dont need the xml file copying becasue thats already in the correct location so some how I need to get then jpg.txt out of here C:\PROGRAM FILES\Image text Editor\photos\ and into here C:\PROGRAM FILES\Image text Editor\

    So would it be best just to copy the one folder?

  18. #18
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: copy a created file to another location.

    I dont know what file you want to copy but play with this ..

    FileCopy mp3path & "jpg.txt", xmlpath & "jpg.txt"

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: copy a created file to another location.

    aesome that works exactly how I wanted to - thanks very much for all your help with this one. Well 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