 |
 |
|

11-27-2002, 01:55 AM
|
|
|
copy files from folder to folder
|
what is the easist way to copy files from one folder to another folder useing names from a text box.....
what i mean by names in a text box is i have the names of the .BMP files in a text box on my form.....
then i will have the path that the actull textures are in...
so i need to pull the texture files from the folder to another folder?
also is it just me or are these boards reaaaaaaaalll slow loading at night
|
|

11-27-2002, 02:13 AM
|
 |
Centurion
|
|
Join Date: Nov 2002
Location: Australia
Posts: 117
|
|
|
try filecopy (path,newpath)
yes, they are slow
|
__________________
every jumbled pile of person has a thinking part that wonders what the part that isn't thinking isn't thinking of...
|

11-27-2002, 03:33 AM
|
|
|
well this is what im trying and im getting file not found.....
Code:
Private Sub Command5_Click()
Dim fs
Set fs = CreateObject("scripting.filesystemobject")
FileName = Text1.Text
Debug.Print FileName
fs.MoveFile FileName, Text2.Text
End Sub
filename is the text box that has the name of the file in it...actully there is a list of names...
and the source dir of where that filename would be is held in a text box called txtDir.text
so i tried this but it came out file not found too
filename = "txtDir.text" + "\" + text1.text
|
|

11-27-2002, 03:49 AM
|
|
|
|
ok i know im on the right track here i can just smell it...
this is what i need to do in a nut shell.....
i have 1 folder "textures"
inside that folder are textures and 2 subfolders called "decals" and "sprites"
i need to take the names i have in the textbox all of them and search through the three folders to pull out the bmp or tga file that has the same name....
my problem is this they can be in either of the three files and they can be either a tga file or a bmp file....
im thinking i have to do a recursive search before i do the copyfile process.....
|
|

11-27-2002, 06:03 PM
|
|
|
|
ok maybe i should go about this a diff way.....
would it be better if i opened alll three folders first and read in all the files in those three folders....so that they are in a array of some sort....
problem with this is that the total of all three files can be large..as i have over 2000 textures in just normal texture folder...
|
|

11-27-2002, 06:08 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
I have a recursive example in tutors corner, but for something like this, hardcoding isn't that terrible....
If you are planning on MOVING (not copying) the files from one dir to another ON THE SAME DRIVE, you might consider the NAME function. Otherwise, try the FileCopy statement.
I don't really see the point of calling the fso for something simple like this....
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

11-27-2002, 06:16 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Simple example:
Code:
Private Sub CopyFile(Byval fn as string, byval DestDir as string)
'copies file(s) fn.* from 3 fixed directories to destdir
Dim srcDir as string
Dim s as string
if Right$(DestDir,1) <> "\" then DestDir = DestDir & "\"
srcDir = "c:\Textures\"
s = Dir$(s & fn & ".*")
While Len(s) 'while s is not null
FileCopy srcDir & fn, DestDir & fn
s = Dir$ 'get another file
Wend
srcDir = "c:\Textures\Decals\"
s = Dir$(s & fn & ".*")
While Len(s) 'while s is not null
FileCopy srcDir & fn, DestDir & fn
s = Dir$ 'get another file
Wend
srcDir = "c:\Textures\Sprites\"
s = Dir$(s & fn & ".*")
While Len(s) 'while s is not null
FileCopy srcDir & fn, DestDir & fn
s = Dir$ 'get another file
Wend
End Sub
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

11-27-2002, 06:38 PM
|
|
|
|
ok im gonna give your code a try question i have about it is the name of the file that i need to copy(not move that was my mistake) is in a text box on my application...there is a list of names in the textbox....those are all the ones i need to copy out of one of the folders....so do i need to place that in anywhere....
|
|

11-27-2002, 06:50 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
First, a caveat: I wrote this on the fly so it is UNTESTED.
Anyway, it's written as a sub (copyfile fn, destdir) so all you need to do is have another sub and call it in a loop:
Code:
dim i as integer
dim names as string
dim aFn() as string 'array of strings
names = text1.text 'collect the names into a single string
'PRESUMABLY you've separated the names somehow, maybe by crlf or tabs or spaces or commas.
' If not, you got a problem....
aFn = Split(names," ") 'assumes filenames are separated by spaces
For i = 0 to ubound(aFn)
if len(aFn(i)) then 'simple error check
CopyFile aFn(i), "c:\temp\"
end if
next i
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

11-27-2002, 07:02 PM
|
|
|
|
ok thanks bill for the help...its giveing me a file path not found....
i think this little adventure i took on was way past my noobie skills so i think im gonna just hang in the towel....but thank you for replying.....
|
|

11-28-2002, 02:55 AM
|
|
|
can someone let me know how do you loop through a text box...
i know for a file it would be while not EOF but i need to loop teh above code in my command button_click and its reading out of a text box....
Code:
Private Sub Command5_Click()
Dim i As Integer
Dim names As String
Dim aFn() As String 'array of strings
names = Text1.Text 'collect the names into a single string
'PRESUMABLY you've separated the names somehow, maybe by crlf or tabs or spaces or commas.
' If not, you got a problem....
aFn = Split(names, vbCrLf) 'assumes filenames are separated by spaces
Do
For i = 0 To UBound(aFn)
If Len(aFn(i)) Then 'simple error check
FileCopy txtDir.Text & "\" & aFn(i) & ".tga", "c:\textures"
End If
Next i
Loop
End Sub
this is what im useing and its giveing me a path/file axcess error..when i hold the cursor over the aFn(i) it shows the file and the correct path and the file is in that folder to copy it...do i have the .tga part wrong...couse in the text box it just has the name not the file ext...
|
Last edited by sirbum69; 11-28-2002 at 03:39 AM.
|

11-28-2002, 04:03 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
That Do Loop you put in will cause your program to lock up since it will run infinitely....it's a good thing you get a file error; otherwise, you could fill up your hard drive.
I see you are using FileCopy. I seem to recall that it requires a name of a file, not just a directory to work.
src=TxtDir.Text & "\" & aFn(i) & ".tga"
dest = "c:\textures\" & aFn(i) & ".tga"
Debug.print "copying from ";src;" to ";dest
FileCopy src, dest
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

11-28-2002, 04:07 AM
|
|
|
|
lol that would not have been a good thing.....i can see it now i had 3 gigs now i have nothing....ok ill give this a shot....
see what happens....one other quick question on this line...if there is a chanve that the file is either of the two... .bmp or .tga can that be added in there so that it will look for either...reason i ask is couse i know that the first one in the list is a .tga but i dont know what the 2nd and so forth is...i just know that for sure it will either be a tga or a bmp...
|
|

11-28-2002, 04:19 AM
|
|
|
|
well that worked like a charm finnaly....it went through and copied the first 5 till it hit a texture it couldnt find in the deacls folder which is why i was trying to work on the looking in all three folders.....
|
|

11-28-2002, 04:34 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
Hmmm.....you do realize that I gave you code for TWO functions? The one you are using was supposed to call the other one (CopyFile). That one should be able to go into the subdirectories and find all the .tga or .bmp files required.....
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

11-28-2002, 05:23 AM
|
|
|
Code:
Private Sub CopyFile(ByVal fn As String, ByVal DestDir As String)
'copies file(s) fn.* from 3 fixed directories to destdir
Dim srcDir As String
Dim s As String
If Right$(DestDir, 1) <> "\" Then DestDir = DestDir & "\"
srcDir = "c:\Sierra\SWAT3\Missions\sample\mission\texture\"
s = Dir$(s & fn & ".*")
While Len(s) 'while s is not null
FileCopy srcDir & fn, DestDir & fn
s = Dir$ 'get another file
Wend
srcDir = "c:\Sierra\SWAT3\Missions\sample\mission\texture\decals\"
s = Dir$(s & fn & ".*")
While Len(s) 'while s is not null
FileCopy srcDir & fn, DestDir & fn
s = Dir$ 'get another file
Wend
srcDir = "c:\Sierra\SWAT3\Missions\sample\mission\texture\sprites"
s = Dir$(s & fn & ".*")
While Len(s) 'while s is not null
FileCopy srcDir & fn, DestDir & fn
s = Dir$ 'get another file
Wend
End Sub
Private Sub Command5_Click()
Dim i As Integer
Dim names As String
Dim aFn() As String 'array of strings
Dim src As String
Dim dest As String
names = Text1.Text 'collect the names into a single string
'PRESUMABLY you've separated the names somehow, maybe by crlf or tabs or spaces or commas.
' If not, you got a problem....
aFn = Split(names, vbCrLf) 'assumes filenames are separated by spaces
For i = 0 To UBound(aFn)
If Len(aFn(i)) Then 'simple error check
src = CopyFile
dest = CopyFile
Debug.Print "copying from "; src; " to "; dest
FileCopy src, dest
End If
Next i
End Sub
ok that is what i have there now...and it said argument not optional and highlighted where i put src= copyfile
|
|

11-28-2002, 12:33 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
OK.....I see that you might be a bit new to subroutines....
When you create a function or sub, you define it's parameters (or argument list) and it's return value. The only difference between subs and functions is that subs have no return value, but both MAY have parameters.
In this case, the CopyFile sub has been defined as:
Private Sub CopyFile(ByVal fn As String, ByVal DestDir As String)
This means
- there are 2 parameters required, fn and DestDir
- they are both strings
- The BYVAL indicates that a COPY of the actual variable is made and used within the function. It would be similar to:
fn = filename
now both fn and filename contain the same value and we can modify fn WITHOUT modifying filename since fn is just a copy. In contrast, passing a variable BYREF means that a pointer to the ACTUAL variable is passed in. In that case, modifying fn WILL modify filename.
Anyway, CopyFile has been defined as a sub that requires 2 parameters and returns NO value.
So all you have to do is pass the filename and the destination directory to the sub. You can do that in the click event you have.
Code:
Private Sub Command5_Click()
Dim i As Integer
Dim names As String
Dim aFn() As String 'array of strings
names = Text1.Text 'collect the names into a single string
'PRESUMABLY you've separated the names somehow, maybe by crlf or tabs or spaces or commas.
' If not, you got a problem....
aFn = Split(names, vbCrLf) 'assumes filenames are separated by spaces
For i = 0 To UBound(aFn)
If Len(aFn(i)) Then 'simple error check
CopyFile aFn(i), "c:\textures\"
End If
Next i
End Sub
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

11-28-2002, 12:56 PM
|
|
|
|
ok but see whats happning and the reason i thought it wasnt working is couse when i put the code above in the click event...
and i hit the button nothing happens....i dont get an error but it doesnt copy the files from the source to the dest folder....
and where i was understanding something else is that no where in the copyfile sub do i see a refrence to what fn is...i see it used in the function but i dont see anywhere where it says something like
fn= filname....
|
|

11-28-2002, 01:14 PM
|
|
|
ok and i just used the step into debugging to look at each step as it went through.....
and for the line that says copyfile afn(i) the afn(i) shows the name of the first file to be copied....as "1_graf_decal" then it steps out of it....so the statement
Code:
copyfile afn(i), "c:\textures"
to me looks like it should do the event filecopy couse in the sub for copy file it has the code FileCopy.....so im not seeing why its not doing it.....
and your right i havnt had much in the way of working with sub routines other then just as a event driven thing....another words ive always coded what i wanted right under the event .....click etc..but im trying to learn it....lol....much as it seems that im not...
|
|

11-28-2002, 01:17 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Well, I said it was untested.....I took another look and found a typo in CopyFile:
s = Dir$(s & fn & ".*")
Should be:
s = Dir$(srcDir & fn & ".*")
In 3 places.
(BTW: It's still untested  )
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|