From: Jake on
Den 10.03.2010 10:13, skreiv Pegasus [MVP]:

> With oFSO it's usually the .Name property that gives you the file or
> folder name

THAT did the trick! Thanks a lot Pegasus :-)
From: "Dave "Crash" Dummy" on
Jake wrote:
> Hi,
>
> I have a folder called E:\MyFolder which contains an arbitrary number of
> subfolders like Sub1, Sub2 Sub3 etc.
>
> In each of these folders there might be a file called MyFile.DAT.
>
> I need a script that loops through all levels of subfolders under
> E:\MyFolder and copies every occurrence of MyFile.DAT to E:\Target. In
> the copying process each Myfile.DAT is renamed according to the
> subfolder it was found in, like: Sub1-Myfile.DAT, Sub2-Myfile.DAT etc...
>
> How would I do that in vbscript...?

Better late than never:
'===========================================
set fso = CreateObject("Scripting.FileSystemObject")
set root=fso.getFolder("E:\MyFolder")

call folderlist(root)

sub folderlist(grp)
call filelist(grp)
for each fldr in grp.subFolders
set nf=fso.GetFolder(fldr.path)
call folderlist(nf)
set nf=nothing
next
end sub

sub filelist(grp)
for each file in grp.files
if file.name="MyFile.DAT" then
subdir=left(file.path,inStrRev(file.path,"\"))
set folder=fso.getFolder(subdir)
target="E:\Target\" & folder.name & "-" & file.name
file.copy target
end if
next
end sub
'===========================================

--
Crash

English is not my native tongue; I'm an American.