In my office we have a system for allocating work that involves
creating a subfolder based on a reference number.

The reference number forms a unique part in the format T#nnnnn at the
start of the folder name, the rest of the folder name is freeformat
text with a description of the task (eg "T#12345 - Set up vbscript"). I
am trying to write a script that will check if a folder exists for a
given reference number, if it does it opens it up in explorer and if it
doesn't, it creates the folder and asks the user to input a description
which is then used in the folder name.

The only way I've been able to do it is to get a list of all the
subfolders and loop through each one checking the first 7 characters,
however this is taking quite a while as we have thousands of these
things.

I have split the folders into ranges of 1000 but it still takes too
long to find. What i'd really like to do is to only return folders with
a name of T#nnnn* when I do the getfolder. I can't seem to find any
other method on the filesystemobject that will do this. Wuld be very
grateful if someone could help me. Ta.

Re: Checking for folder existence using widlcards by Jerold

Jerold
Thu Mar 16 09:31:35 CST 2006

On 16 Mar 2006 04:04:08 -0800, "CTM" <closerthanmost@ukf.net> wrote:

>In my office we have a system for allocating work that involves
>creating a subfolder based on a reference number.
>
>The reference number forms a unique part in the format T#nnnnn at the
>start of the folder name, the rest of the folder name is freeformat
>text with a description of the task (eg "T#12345 - Set up vbscript"). I
>am trying to write a script that will check if a folder exists for a
>given reference number, if it does it opens it up in explorer and if it
>doesn't, it creates the folder and asks the user to input a description
>which is then used in the folder name.
>
>The only way I've been able to do it is to get a list of all the
>subfolders and loop through each one checking the first 7 characters,
>however this is taking quite a while as we have thousands of these
>things.
>
>I have split the folders into ranges of 1000 but it still takes too
>long to find. What i'd really like to do is to only return folders with
>a name of T#nnnn* when I do the getfolder. I can't seem to find any
>other method on the filesystemobject that will do this. Wuld be very
>grateful if someone could help me. Ta.

This is easily done in a batch script.
I am assuming that the parent folder is c:\folder, so that each T#12345 is
"c:\folder\T#12345 - This is the one"

@echo off
if {%1}=={} @echo Syntax RefExist T#nnnnn&goto :EOF
setlocal
set Tnum=%1
set Tnum=%Tnum:"=%
if exist c:\folder\%Tnum%* goto openit
set /p ans=Please enter a description for %Tnum%
md "c:\folder\%Tnum% - %ans%"
:openit
for /f "Tokens=*" %%a in ('dir /b /ad c:\folder\%tnum%*') do (
start Explorer.exe /n,/root,"c:\folder\%%a"
)
endlocal




Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com

Re: Checking for folder existence using widlcards by CTM

CTM
Fri Mar 17 04:03:28 CST 2006

Thanks very much...can't get it to work though!

I do need to do this in VBS though. I think I'll have to think it out
again.


Re: Checking for folder existence using widlcards by Keith

Keith
Fri Mar 17 13:38:46 CST 2006

You might have better luck with the objects found here:

http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/objects/objects.asp

Specifically, the filter method will allow you to narrow the folders you check to those beginning
with "T#"

This may get you part way there....

Const SHCONTF_FOLDERS = &HA0

Set oShell = CreateObject("Shell.Application")

set oFolder = oShell.BrowseForFolder(0, "Choose a Folder", 0)
' or set oFolder = oShell.NameSpace("C:\path\to\folder")

set oSubFolderItems = oFolder.Items
oSubFolderItems.Filter SHCONTF_FOLDERS, "T#*"

bFolderFound = False
For each Item in oSubFolderItems
If Mid(Item.Name, 3, 5) = CStr(ReferenceNumber) Then
bFolderFound = True
oShell.Open Item.GetFolder
Exit For
End If
Next

If Not bFolderFound Then
'create new folder
End If


--
Good Luck,

Keith
Microsoft MVP [Windows XP Shell/User]


"CTM" <closerthanmost@ukf.net> wrote in message
news:1142510648.863064.25490@i39g2000cwa.googlegroups.com...
> In my office we have a system for allocating work that involves
> creating a subfolder based on a reference number.
>
> The reference number forms a unique part in the format T#nnnnn at the
> start of the folder name, the rest of the folder name is freeformat
> text with a description of the task (eg "T#12345 - Set up vbscript"). I
> am trying to write a script that will check if a folder exists for a
> given reference number, if it does it opens it up in explorer and if it
> doesn't, it creates the folder and asks the user to input a description
> which is then used in the folder name.
>
> The only way I've been able to do it is to get a list of all the
> subfolders and loop through each one checking the first 7 characters,
> however this is taking quite a while as we have thousands of these
> things.
>
> I have split the folders into ranges of 1000 but it still takes too
> long to find. What i'd really like to do is to only return folders with
> a name of T#nnnn* when I do the getfolder. I can't seem to find any
> other method on the filesystemobject that will do this. Wuld be very
> grateful if someone could help me. Ta.
>


Re: Checking for folder existence using widlcards by CTM

CTM
Mon Mar 27 05:01:36 CST 2006

Fantastic. This cut the response time down from about 45 seconds to
about 2. Thanks very much.