Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi again folks!
I am looking for a batch file to be able to return folder name(s) within a given location.
I have a static location (C:\MyFolder\Mysub1\Mysub2\base_v6\profiles\default\installedApps)
WITHIN this folder resides at least one additional folder. Each folder is named <PCName>Node01Cell.
There is usually only one folder in there. Lets call it "FirstNode01Cell". Where "First" = a PC Name. I need to return to a variable, "First".
Here's where it gets tricky...
There is usually only ONE folder in this location, but on ocassion there may be several. I would like to be able to return the last (3) by date? (Var1, Var2, Var3)
Is this possible? And/or if there were only and ever (1) folder in this location, how would I return the portion of the folder name that I am looking for?
Best regards and many thanks in advance!
Rbsterli

I use MindVision Installer Vise to install applications and make executable utilitys.. This application has certain limits and that where I need batch files to assist..
Anyhow, what I am trying to do here is.. I have an IBM application that I frequently install. It must be installed per machine because during the installation in creates folders and files based on CURRENT machine name.
I want to image this machine and deploy to others. To do this, I need to rename each folder with the text string of the PC name it had during the install, to the text string of the new/existing machine.
Now what I am really trying to do here is:
When this app installs, it creates a folder called <machine name>Node01 in a given location each time. I am looking to obtain the text string(s) of <machine name> from all existing folders in this location. I want to use these variables as items in a drop down box in my Installer Vise application.I want to give them a choice of potential previous names to choose from so they don't have to go look manually.
Any thoughts?? Thanks!!
EDIT: After thoughts..
If I could just search that static location above for any folders that are named *Node01Cell, then return the prefix characters of those folder names... (thinking out loud at this point)..
Loop through them a maximum of 5 times.

And how were you planing on getting the variables from the batch script to Vise's drop down?
Actually, I'm also wondering how the install changes from machine to machine. If it's just some entries in a text file and/or registry, it'd probably be easier to set up a script that runs from your installer and changes the machine name appropriately.

Where you would "echo" the variables, I would REG ADD them and then read them.
The installer is an IBM installer and I cannot change that. The install changes from machine to machine as I mentioned. The first install creates a series of folders and XML files. All contain the current machine name.
I already have a method to find and replace these. (I would be happy to share if you are an Installer Vise person).
If you wish, you can email me directly or go to my forum and we can discuss there... Thanks again for your help.

[code]
Option Explicit
Dim objFSO,staticPath,objFolder,index,FName,searchString
Dim FolderCount,c,Folders,j,i,temp
Set objFSO = CreateObject("Scripting.FileSystemObject")
staticPath = "C:\test1"
searchString = "Node"
Dim fNames()
FolderCount = objFSO.GetFolder(staticPath).SubFolders.Count
If FolderCount = 0 Then
WScript.Echo "No folders.."
WScript.Quit
ElseIf FolderCount >= 1 Then
ReDim fNames(FolderCount)
c=0
For Each Folders In objFSO.GetFolder(staticPath).SubFolders
FName = getPCName(Folders.Name)
fNames(c)=UDate(Folders.DateLastModified)&"|"&FName
c=c+1
Next
Sort(fNames) 'sort the array
For j = LBound(fNames) To UBound(fNames) - 1
'print PC Names along with their date/time in secs
WScript.Echo "PC Names: ",fNames(j)
If j=2 Then 'get last 3 latest pc names
WScript.Quit
End If
Next
End IfFunction getPCName(folderName)
'Function to get PC Name
index= InStr(1,folderName,searchString)
getPCName = Left(folderName,index-1)
End FunctionSub Sort(theArray)
'little function to sort Array
For j = LBound(theArray) To UBound(theArray) - 1
if theArray(j)<=theArray(j+1) then
temp=theArray(j+1)
theArray(j+1)=theArray(j)
theArray(j)=temp
End If
Next
End SubFunction UDate(oldDate)
'convert date to seconds after epoch, for easier comparison
UDate = DateDiff("s", "01/01/1970 00:00:00", oldDate)
End Function[/code]

::== INCvar4.bat
:: gets machine names into vars v1 v2 v... [increment]@echo off
setLocal EnableDelayedExpansionpushd "C:\MyFolder\Mysub1\Mysub2\base_v6\profiles\default\installedApps"
for /f "tokens=* delims= " %%a in ('dir /b/ad') do (
set /a n+=1
set str=%%a
set str=!str:Node01Cell=!
set v!n!=!str!
)set v
::== DONE
=====================================
If at first you don't succeed, you're about average.M2

WOW! Thanks. I tried both but the shorter one will work much better and very efficient in my case. Thanks so much!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |