Author Topic: copy files to the right folder  (Read 2211 times)

0 Members and 1 Guest are viewing this topic.

Humbertogo

  • Guest
copy files to the right folder
« 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?

Atook

  • Swamp Rat
  • Posts: 1030
  • AKA Tim
Re: copy files to the right folder
« Reply #1 on: October 31, 2007, 01:11:20 PM »
I'm not understanding you, perhaps you could post a screenshot of your folder tree?

Humbertogo

  • Guest
Re: copy files to the right folder
« Reply #2 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


« Last Edit: October 31, 2007, 03:15:10 PM by Humbertogo »

Bob Wahr

  • Guest
Re: copy files to the right folder
« Reply #3 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.

Bob Wahr

  • Guest
Re: copy files to the right folder
« Reply #4 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.

Bob Wahr

  • Guest
Re: copy files to the right folder
« Reply #5 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.

ML

  • Guest
Re: copy files to the right folder
« Reply #6 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

Bryco

  • Water Moccasin
  • Posts: 1883
Re: copy files to the right folder
« Reply #7 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)

ML

  • Guest
Re: copy files to the right folder
« Reply #8 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.



ML

  • Guest
Re: copy files to the right folder
« Reply #9 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

Bryco

  • Water Moccasin
  • Posts: 1883
Re: copy files to the right folder
« Reply #10 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

ML

  • Guest
Re: copy files to the right folder
« Reply #11 on: November 06, 2007, 01:08:20 PM »

Ahhhhh cool

Thanks Bry!