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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSystemObject, folders, and files... confounding.

Status
Not open for further replies.

Mr3Putt

Programmer
May 27, 2003
320
IN
Note: I have already attempted to peruse the FAQs, and I Googled around for a bit... no luck.

Here's my boggle: While I'm interrogating the content of a folder object, I want to check for the existence of files in another folder. Why I want to do this is mostly unimportant, I'm just curious to find out why my expected method doesn't work.

So, at the top of my junk, I create two folder objects:
Code:
set fs = createobject("Scripting.FileSystemObject")
Set fldr1 = fs.getFolder("\\ServerPath\RefFiles")
set fldr2 = fs.getFolder("\\ServerPath\RefFiles\Root_files")
I use the "fldr1" to begin processing my page by passing it to a function which reads through the files inside, like:
Code:
processFolder fldr1
One of the things I need to know about the files is the .DateLastModified. BUT, if a file (in fldr1) is a "Shortcut" (file name ends with ".lnk"), I want to get the date from the LINKED file (which is hopefully) in the Root_files directory, like:
Code:
function processFolder(fObj)
  for each doc in fldr1.Files
    fpath = doc.Path
    fsize = Round((doc.size/1024),0)
    fname = doc.Name
  [COLOR=red][b]  fmod  = getDocMod(fname, doc.DateLastModified)[/b][/color]
  next
  --- obviously I'm cutting out a bunch of crap here ---
end function

private function getDocMod(fn, fdt)
  dim tn  [COLOR=green]' the template name I'm looking for[/color]
  if right(fn,4) <> ".lnk" then
    getDocMod = fdt [COLOR=green]' not a shortcut, use original date[/color]
  else
    if rootFiles.FileExists(tn) then
      getDocMod = fldr2.getFile(tn).DateLastModified
    else
      getDocMod = fdt  [COLOR=green]' didn't find the template[/color]
    end if
  end if
end function
But, that doesn't work for !@#$.

I was under the impression that I could refer to a File object of the Folder object by name (fldr2.getFile(tn)), but I can't. I know that "fldr2" is an object, because I can process it using the "processFolder" function without issue.

The way I read the specs for "getFile()" is that it checks in the CURRENT folder... which is represented by my fldr2 object. I can retrieve DOCS from the .Files object of it, but I can't seem to REFER to the Docs by name WITHIN it.

Have I snapped my tether, or is this unusual? Obviously the FSO works the way it works, and my railings will not force it to work the way I wish... but I find this confounding.

Any advice, criticism, suggestions, derision are invited.

[red]Note:[/red] [gray]The above comments are the opinionated ravings of Mr3Putt. As such, Mr3Putt accepts no responsibility for damages, real or contrived, resulting from acceptance of his opinions as fact.[/gray]
 
Hello Mr3Putt,

You have dim tn. You have pass variable fn. Then, there is rootFiles.FileExists(tn) where tn is empty. Is that what you want or you cut the thing out?

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top