Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read filenames into an array.

Status
Not open for further replies.

MISMCSA

MIS
Jun 24, 2004
43
US
I'm trying to find a way to make a backup of files within a folder and store them in a second folder.

Here is the scenario I am looking at.

Scenario (better explanation):

A & B are both folders,

I have file1, file2, and file3 in A. I have file2, file3, and file7 in B.

The script has to look at A and B and determine that file1 needs to be copied to B and that file7 needs to be deleted off of B. It also has to while compare file2 and file3, from both A & B to determine if B has the most recent copy.

There could be as litle as 5 files in these folders, or as many as 100.

I'm thinking I need to store the file names from both folders in a string array and then compare the string names to one another.

Any suggestions?
 
Take a look at the FileSystemObject.
You may also consider a shareware program named FolderMatch:

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I need this in a vbscript so it can be given to our users to back up there critical files. this folder transfer is just part of the entire vbscript.

I can't get the filesystemobject to accomplish what I want. I'm sure thisis do to my inexperience with vbscript.
 
How do store the file names of iles in a folder into a text document so I can search the files as strings?
 
Robocopy is a NTReskit utility. It does exactly what you are looking for and there is numerous scripts on the web that use it.

Hope that helps. I use it to manage backups overnight back to our NAS units. So we can backup centrally onto tape.

 
This utility is installed by default on all microsoft OSs?
 
No --> I just checked my OS and no Robocopy. :)

You need to obtain it. By the way the new version that comes with the new Win2003 resource kit. Does throttling as well so you can control bandwith usage.

Cool.
 
Thanks for your suggestions, but I need to do this in a way that will not require additional installation of software. It has to be a script that is easily run by our 3000 users.
 
Could someone tell me if this is a feasible plan. Can I use a loop to run code that will grab the filename of every file within in a folder and store it into an array. Then do the same for another folder and search for a filename from the first folder in the second folder?

How would I go about starting this off?
 
How would I go about starting this off?
Do a keyword search in this forum for fso recursive
Take a look at the Dictionary object too.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Come up with some code or at least some pseudo code and post it back here and you will get more help.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
If I want a loop to end once all of the file names, within a folder, have been stored in an array. What statement do I use?

I have looked up information, but keep finding the same stuff on read to end of file.
 
Once they're all stored in an array you would loop from start to end by using:

Code:
'Assuming your array is called arFilenames..
For i = Lbound(arFilenames) to Ubound(arFilenames)
     msgbox arFilenames(i)
Next
 
Once they're all stored in an array you would loop from start to end by using:

Code:
'Assuming your array is called arFilenames..
For i = Lbound(arFilenames) to Ubound(arFilenames)
     msgbox arFilenames(i)
Next
 
Sorry I think I miss-read that... The statement to exit a "Do... Loop" is "Exit Do
 
I'm a real novice in this area. The scripting/programing is not a strong area for me yet.

I know this is incorrect.

Dim localArray()
Dim intIndex
intIndex = 0
Do
localArray(intIndex) = fso.GetFileName("c:\Test")
intIndex + 1
Loop
 
Try something like this:
(untested code)
[/code]
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\Path\To\Your\Folder")
Set colFiles = oFolder.Files
i = 0
Dim arrFiles(i)
For Each oFile In colFiles
arrFiles(i) = oFile.Name
WScript.Echo "arrFiles(" & i & ") = " & arrFiles(i)
i = i + 1
Redim Preserve arrFiles(i)
Next
[/code]

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Listen guys I can only echo again. Robocopy -> it does not need installed. Just needs to be copied to the machines.

tiny : 78KB

Your script will probably end up larger than this anyway.
 
Sorry I didn't post back, but I did choose to use robocopy afterall. I through it up on a file server that all associates have access to and then called it from the script. It is working very well like this and required significantly less scripting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top