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

Another script request if anyone can help

Status
Not open for further replies.

getme001

Vendor
Aug 21, 2014
5
US
I am looking for a script to ask to enter a folder name. It needs to search in c:/ for the folder name entered. If it finds it to open it, if not to say file not found. Is this possible.
Thank you for your help. :)
 
Thank you for the reply. Im sorry, it needs to say folder not found. I am worried more about the folder than the files. I can do this now but I can not search in folders and subfolders within the directory specified.
 
I have the following code that open the folder by entering the name of the main folder, then by entering the name of the subfolder. However, I need it to enter the name of one folder and then it needs to search in the main folder to locate the folder if it exists and then open it.

CONST strDir = "c:\test"

set objShell = CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")

function findFolder(strDir, strFlag1)
set objFolder = objFSO.GetFolder(strDir)
for each objSubFolder in objFolder.SubFolders
if (inStr(objSubFolder.Name, strFlag1)) then
findFolder = objSubFolder.Path
exit function
else
findFolder = findFolder (objSubFolder.Path, strFlag1)
end if
next
end function


strFlag1 = inputBox("Enter Client")
strFlag2 = inputBox("Enter case")
strWeb = findFolder(strDir, strFlag1) & "\" & strflag2
objShell.Run strWeb
 
Hi [peace]
Try this batch file :

Code:
@echo off
Title Search for a folder by name and open it with Explorer by Hackoo 2014
mode con cols=75 lines=3 & color 9B
Set /p FolderName2Search=Please Enter the keyword to find :
Set MyListFolder=ListFolder.txt
Set ResultFolder=ResultFolder.txt
Call :BrowseFolder "Select the Source folder" "C:\Program"
Set StartFolder=%Result%
cls
Echo Looking for a folder that contains the string "%FolderName2Search%". . .
Dir %StartFolder% /b /a:d /s > %MyListFolder%
Findstr /r "%FolderName2Search%" %MyListFolder% > %ResultFolder%
Setlocal Enabledelayedexpansion
set "file=%ResultFolder%"
for /F "delims=" %%a in (%file%) do (
    set /A count+=1
    set "array[!count!]=%%a"
)
cls
For /L %%i in (1,1,%count%) do echo "!array[%%i]!" & Start Explorer "!array[%%i]!" & Pause & cls
Exit /b

:BrowseFolder
    set Result=
    set vbs="%temp%\_.vbs"
    set cmd="%temp%\_.cmd"
    for %%f in (%vbs% %cmd%) do if exist %%f del %%f
    for %%g in ("vbs cmd") do if defined %%g set %%g=
    >%vbs% echo set WshShell=WScript.CreateObject("WScript.Shell") 
    >>%vbs% echo set shell=WScript.CreateObject("Shell.Application") 
    >>%vbs% echo set f=shell.BrowseForFolder(0,%1,0,%2) 
    >>%vbs% echo if typename(f)="Nothing" Then  
    >>%vbs% echo wscript.echo "set Result=Dialog Cancelled" 
    >>%vbs% echo WScript.Quit(1)
    >>%vbs% echo end if 
    >>%vbs% echo set fs=f.Items():set fi=fs.Item() 
    >>%vbs% echo p=fi.Path:wscript.echo "set Result=" ^& p
    cscript //nologo %vbs% > %cmd%
    for /f "delims=" %%a in (%cmd%) do %%a
    for %%f in (%vbs% %cmd%) do if exist %%f del %%f
    for %%g in ("vbs cmd") do if defined %%g set %%g=
::******************************************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top