TheSwamp

Code Red => VB(A) => Topic started by: Humbertogo on October 31, 2007, 07:32:59 AM

Title: copy files to the right folder
Post 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?
Title: Re: copy files to the right folder
Post by: Atook on October 31, 2007, 01:11:20 PM
I'm not understanding you, perhaps you could post a screenshot of your folder tree?
Title: Re: copy files to the right folder
Post by: Humbertogo on October 31, 2007, 03:11:54 PM
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


Title: Re: copy files to the right folder
Post by: Bob Wahr on October 31, 2007, 03:50:27 PM
This should give you a start
Code: [Select]
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.
Title: Re: copy files to the right folder
Post by: Bob Wahr on October 31, 2007, 04:06:51 PM
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.
Title: Re: copy files to the right folder
Post by: Bob Wahr on November 05, 2007, 02:39:19 PM
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.
Title: Re: copy files to the right folder
Post by: ML on November 05, 2007, 06:39:10 PM

Hi Bob
He did say copy but otherwise, it lookslike you nailed it.
The FSO object is very helpful

Mark
Title: Re: copy files to the right folder
Post by: Bryco on November 05, 2007, 08:12:34 PM
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)
Title: Re: copy files to the right folder
Post by: ML on November 06, 2007, 09:41:40 AM

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.


Title: Re: copy files to the right folder
Post by: ML on November 06, 2007, 09:42:38 AM

I see, I think the function isnumeric will look at a string of text and grab the numeric values?

Mark
Title: Re: copy files to the right folder
Post by: Bryco on November 06, 2007, 01:01:24 PM
IsNumeric returns True if the entire expression is recognized as a number; otherwise, it returns False.

It doesn't grab the numeric values
Title: Re: copy files to the right folder
Post by: ML on November 06, 2007, 01:08:20 PM

Ahhhhh cool

Thanks Bry!