TheSwamp
Code Red => VB(A) => Topic started by: Humbertogo on October 31, 2007, 07:32:59 AM
-
i have a number of folders this are project names
the folders name are for example 100_250 that main
that in this folder are project files from 100 to 250
25_99
100_250
But know i need to one project in the right folder for example
i need to copy project number 30 and 175 to the right folder
how to do that?
-
I'm not understanding you, perhaps you could post a screenshot of your folder tree?
-
another way like this
i need to copy project number 30 and 175 to the right folder
'project 30
If 30 > 25 And 99 > 30 Or 30 = 25 Or 99 = 30 Then
in to folde 25_99
'project 175
If 175 > 100 And 250 > 175 Or 175 = 100 Or 250 = 175 Then
in to folde 100_250
folder tree
Projects
- 25_99
-100_250
-
This should give you a start
Sub test()
Dim objFS As Object
Dim objDrive As Object
Dim objFldrs As Object
Dim objFldr As Object
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objDrive = objFS.GetFolder("C:\")
Set objFldrs = objDrive.subfolders
For Each objFldr In objFldrs
If objFldr.Name < 100 Then
objFldr.MoveFolder objFldr.Path, "c:\25_99\" & objFldr.Name
ElseIf objFldr.Name < 251 Then
objFldr.MoveFolder objFldr.Path, "c:\100_250\" & objFldr.Name
End If
Next objFldr
End Sub
Not tested but should be pretty close.
-
Just noticed the name of the thread didn't match my answer. You'll want to use the CopyFolder method instead of MoveFolder if copying is what you want to do.
-
I'm guessing by the lack of follow up that I was either close enough that you got it to work or far enough that you gave up.
-
Hi Bob
He did say copy but otherwise, it lookslike you nailed it.
The FSO object is very helpful
Mark
-
Since the string "11" >"100" it's best if you convert the file names to integers before doing your check.
if isnumeric(filename) then ifile=cint(filename)
-
So you are saying, he should declare objFldr as Integer?
Dim objFldr As Integer
Is so, that makes sense
However, the objFldr.Path is a string
I noticed with VBSripting language, data types aren't really used much, at least what I have seen.
When I use or bring scripting code into VBA, I do try to assign the correct data types instead of just using object or variable for the nec. reasons and to avoid using Variant too much.
-
I see, I think the function isnumeric will look at a string of text and grab the numeric values?
Mark
-
IsNumeric returns True if the entire expression is recognized as a number; otherwise, it returns False.
It doesn't grab the numeric values
-
Ahhhhh cool
Thanks Bry!