Computing.Net > Forums > Programming > FInd folder names

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

FInd folder names

Reply to Message Icon

Name: rbsterli
Date: July 6, 2007 at 18:02:41 Pacific
OS: XP
CPU/Ram: NA
Product: NA
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: July 6, 2007 at 18:13:49 Pacific
Reply:

This would be easier in any other scripting language. What are you attempting to do?


0

Response Number 2
Name: rbsterli
Date: July 6, 2007 at 18:24:04 Pacific
Reply:

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.


0

Response Number 3
Name: Razor2.3
Date: July 6, 2007 at 18:55:17 Pacific
Reply:

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.


0

Response Number 4
Name: rbsterli
Date: July 6, 2007 at 19:40:22 Pacific
Reply:

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.


0

Response Number 5
Name: ghostdog
Date: July 7, 2007 at 02:31:52 Pacific
Reply:


[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 If

Function getPCName(folderName)
'Function to get PC Name
index= InStr(1,folderName,searchString)
getPCName = Left(folderName,index-1)
End Function

Sub 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 Sub

Function UDate(oldDate)
'convert date to seconds after epoch, for easier comparison
UDate = DateDiff("s", "01/01/1970 00:00:00", oldDate)
End Function

[/code]


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: July 7, 2007 at 04:12:33 Pacific
Reply:

::== INCvar4.bat
:: gets machine names into vars v1 v2 v... [increment]

@echo off
setLocal EnableDelayedExpansion

pushd "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



0

Response Number 7
Name: rbsterli
Date: July 7, 2007 at 07:31:31 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: FInd folder names

get current folder name in var (DOS www.computing.net/answers/programming/get-current-folder-name-in-var-dos/16421.html

folder name & number of files www.computing.net/answers/programming/folder-name-number-of-files/18201.html

Need help with finding folders www.computing.net/answers/programming/need-help-with-finding-folders/18527.html