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:
Private Sub Command2_Click()
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
Dim myFolder As String, mytext As String
myFolder = "photos/"
mytext = "your image Description here"
mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
xmlpath = "C:\PROGRAM FILES\Image text Editor\"
f2 = FreeFile
Open mp3path & "jpg.txt" For Output As #f2 ' if you don't need mp3.txt take out
f1 = FreeFile
Open xmlpath & "album.xml" For Output As #f1
Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
Print #f1, "<slides>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
'Print #f1, "<photo>"
Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
Print #f2, songname
Sleep 100 ' slight pause, needed
songname = Dir ' get next image
'Print #f1, "</photo>"
Wend
Print #f1, "</slides>"
Close
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...
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)
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
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:
Private Sub Command2_Click()
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
Dim myFolder As String, mytext As String
myFolder = "photos/"
mytext = "your image Description here"
mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
xmlpath = "C:\PROGRAM FILES\Image text Editor\"
f2 = FreeFile
Open mp3path & "jpg.txt" For Output As #f2 ' if you don't need mp3.txt take out
f1 = FreeFile
Open xmlpath & "album.xml" For Output As #f1
Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
Print #f1, "<slides>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
'Print #f1, "<photo>"
Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
Print #f2, songname
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
'Print #f1, "</photo>"
Wend
Print #f1, "</slides>"
FileCopy "C:\PROGRAM FILES\Image text Editor\photos\jpg.txt", "C:\PROGRAM FILES\Image text Editor\"
Close
End Sub
Re: copy a created file to another location.
Close the jpg file before you try to copy it. BTW, what is the "Close" you have at the end of your sub?
Re: copy a created file to another location.
To close the file you would do
Close #f2
Re: copy a created file to another location.
VB Code:
Private Sub Command2_Click()
Dim myFolder As String, mytext As String
Dim mp3path As String, xmlpath As String
Dim songname As String, i As Integer
Dim f1 As Integer, f2 As Integer
'/// Dim jpgurl As String, MyPath As String, Artist As String, songpath As String, slidenode As String
myFolder = "photos/"
mytext = "your image Description here"
mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
xmlpath = "C:\PROGRAM FILES\Image text Editor\"
f1 = FreeFile
f2 = FreeFile
Open mp3path & "jpg.txt" For Output As #f2 ' if you don't need mp3.txt take out
Open xmlpath & "album.xml" For Output As #f1
Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
Print #f1, "<slides>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
'Print #f1, "<photo>"
Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
Print #f2, songname
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
'Print #f1, "</photo>"
Wend
Print #f1, "</slides>"
Close #f1
Close #f2
FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
End Sub
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:
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:
Private Sub Command2_Click()
Dim myFolder As String, mytext As String
Dim mp3path As String, xmlpath As String
Dim songname As String, i As Integer
Dim f1 As Integer, f2 As Integer
'/// Dim jpgurl As String, MyPath As String, Artist As String, songpath As String, slidenode As String
myFolder = "photos/"
mytext = "your image Description here"
mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
xmlpath = "C:\PROGRAM FILES\Image text Editor\"
f1 = FreeFile
f2 = FreeFile
Open mp3path & "jpg.txt" For Output As #f2 ' if you don't need mp3.txt take out
Open xmlpath & "album.xml" For Output As #f1
Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
Print #f1, "<slides>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
'Print #f1, "<photo>"
Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
Print #f2, songname
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
'Print #f1, "</photo>"
Wend
Print #f1, "</slides>"
Close #f1
Close #f2
FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
End Sub
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?
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?
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.
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!
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 .. :bigyello:
Thanks, i'll know that now ..
so basically it would be like this ..
VB Code:
Private Sub Command2_Click()
Dim myFolder As String, mytext As String
Dim mp3path As String, xmlpath As String
Dim songname As String, i As Integer
Dim f1 As Integer, f2 As Integer
myFolder = "photos/"
mytext = "your image Description here"
mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
xmlpath = "C:\PROGRAM FILES\Image text Editor\"
f1 = FreeFile
Open xmlpath & "album.xml" For Output As #f1
f2 = FreeFile
Open mp3path & "jpg.txt" For Output As #f2
Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
Print #f1, "<slides>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
'Print #f1, "<photo>"
Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
Print #f2, songname
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
'Print #f1, "</photo>"
Wend
Print #f1, "</slides>"
Close #f1
Close #f2
FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
End Sub
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:
Private Sub Command2_Click()
Dim myFolder As String, mytext As String
Dim mp3path As String, xmlpath As String
Dim songname As String, i As Integer
Dim f1 As Integer, f2 As Integer
myFolder = "photos/"
mytext = "your image Description here"
mp3path = "C:\PROGRAM FILES\Image text Editor\photos\"
xmlpath = "C:\PROGRAM FILES\Image text Editor\"
f1 = FreeFile
Open xmlpath & "album.xml" For Output As #f1
f2 = FreeFile
Open mp3path & "jpg.txt" For Output As #f2
Print #f1, "<?xml version=\""1.0\"" encoding=\""UTF-8\""?>"
Print #f1, "<slides>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
'Print #f1, "<photo>"
Print #f1, "<slideNode jpegURL="""; myFolder; songname; """>"; mytext; "</slideNode>"
Print #f2, songname
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
'Print #f1, "</photo>"
Wend
Print #f1, "</slides>"
Close #f1
Close #f2
FileCopy mp3path & "jpg.txt", xmlpath & "album.xml"
End Sub
Re: copy a created file to another location.
VB Code:
Close #f1
Close #f2
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?
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?
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"
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