Time to learn to find the right folder *sigh*

E

Ed

"Don't hardcode your filepaths" I was told. "But it's only ever going to be on my machine!" I said. Well, it will *still* be only my machine - when IT gives it back, that it. Yesterday, WHAM! and CRASH! Data's good, but tomorrow I get it back with XP and a whole new set-up. *Now* where are my folders and files?!? asks my macros

I can either visit each macro as it errors and hardcode new paths, setting myself up once again for running face-first into brick walls I was told were there! Or I can put a command to the Open dialog and Browse each time - but I have better things to do. Or I can learn how to tell my code to search and find a certain folder or file. I know this means haing to name folders and files in an easily-recognized manner (vice NewFolder2, NewFolder3, Stuff, OldStuff, and other originalities)

*sigh* Okay - where do I start? A drop-kick in the right direction is appreciated

Ed
 
G

Greg Koppel

Hi Ed,

Here are a couple of snippets to get you going.

' Determine if Parthenon\release is mapped on the local machine
Dim fs, d, dc, s, n
Set fs = CreateObject("Scripting.FileSystemObject")
Set dc = fs.Drives
MyDrive = "null"
For Each d In dc
If d.sharename = "\\Parthenon\release" Then
MyDrive = d.Path
Exit For
ElseIf d.sharename = "\\PARTHENON\release" Then
MyDrive = d.Path
Exit For
ElseIf d.sharename = "\\PARTHENON\Release" Then
MyDrive = d.Path
Exit For
ElseIf d.sharename = "\\PARTHENON\RELEASE" Then
MyDrive = d.Path
Exit For
ElseIf d.sharename = "\\Parthenon\Release" Then
MyDrive = d.Path
Exit For
ElseIf d.sharename = "\\parthenon\release" Then
MyDrive = d.Path
Exit For
End If
Next


Sub ShowFinalActive()
Dim fs, f, f1, fc, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("P:\Data\Final\")
Set fc = f.files
For Each f1 In fc
If Left(f1.datelastmodified, Len(Date)) = Str(Date) Then
s = s & f1.Name & vbTab & f1.datelastmodified
s = s & vbCrLf & vbCrLf
End If
Next
MsgBox s, , "Final inspection files modified today"
End Sub

HTH, Greg
Ed said:
"Don't hardcode your filepaths" I was told. "But it's only ever going to
be on my machine!" I said. Well, it will *still* be only my machine - when
IT gives it back, that it. Yesterday, WHAM! and CRASH! Data's good, but
tomorrow I get it back with XP and a whole new set-up. *Now* where are my
folders and files?!? asks my macros!
I can either visit each macro as it errors and hardcode new paths, setting
myself up once again for running face-first into brick walls I was told were
there! Or I can put a command to the Open dialog and Browse each time - but
I have better things to do. Or I can learn how to tell my code to search
and find a certain folder or file. I know this means haing to name folders
and files in an easily-recognized manner (vice NewFolder2, NewFolder3,
Stuff, OldStuff, and other originalities).
 
Top