Click to See Complete Forum and Search --> : Array and build nested directory


wwc_um
February 20th, 2000, 07:41 PM
Question:
1.aryFileName = Array("n01.dbf", "02.dbf", "n03.dbf", "n04.dbf", "n05.dbf")

The code above is define an array of 5 elements. What happen if there are 100 elements? How can I do it in a 'FOR' loop or is there any better solution?


2. How can I created a nested directory?

txtTrgPath is a text box for user to input the pathname

Dim inBackPos As Integer, inForePos As Integer
Dim path
inBackPos = 3
ChDrive txtTrgPath 'Change to current drive
ChDir "\" 'Change to current directory
inForePos = InStr(4, txtTrgPath, "\")
Do While inForePos <> 0
path = Mid(txtTrgPath, inBackPos + 1, inForePos - inBackPos - 1)
MkDir path
ChDir path
inBackPos = inForePos
inForePos = InStr(inBackPos + 1, txtTrgPath, "\")
Loop

The code above is correct if the directory 'Dir', 'Path' and 'Path1', let say c:\Dir\Path\Path1\ doesn't exist

What happen if the directory 'Dir' exist and the directory 'Path' and 'Path1' doesn't exist? How can I correct the problem?


Thanks
Andy

Cakkie
February 20th, 2000, 11:59 PM
1)

for t=0 to 99
' note: your 100th file will be called "n100.dbf", the number will then contain 3 digits
if t < 9 then
' if to small, add a leading 0
aryFileName(t) = "n0" & t + 1 & ".dbf"
else
aryFileName(t) = "n" & t + 1 & ".dbf"
next t




2) add a errorhandler

on error resume next
' when the dir existe, it will generate an error, but will ignore this and
' resume execution at the next statement

Dim inBackPos as Integer, inForePos as Integer
Dim path
inBackPos = 3
ChDrive txtTrgPath 'Change to current drive
ChDir "\" 'Change to current directory
inForePos = InStr(4, txtTrgPath, "\")
Do While inForePos <> 0
path = mid(txtTrgPath, inBackPos + 1, inForePos - inBackPos - 1)
MkDir path
ChDir path
inBackPos = inForePos
inForePos = InStr(inBackPos + 1, txtTrgPath, "\")
Loop





Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.