Computing.Net > Forums > Programming > Scanning / adding numerical folder

Scanning / adding numerical folder

Reply to Message Icon

Original Message
Name: jeremylittman
Date: July 1, 2007 at 20:10:16 Pacific
Subject: Scanning / adding numerical folder
OS: XP sp2
CPU/Ram: Xeon / 2Gb
Model/Manufacturer: Dell Precision
Comment:

I have a list of project folders who's naming convention is as follows:

YY+123+"-"+DESCRIPTION

e.g.

07063-NewCourt
07064-Fetter
07065-7StJames

The sequence no. must have preceding 0's

I would like to create a batch file that does the following:

1. Request the following input while autopopulating the next available sequence number

i.e.

Please enter the description for next available Project no. 07066-:

2. Copy and rename a template project folder with the user input as foldername

3. Copy a template config text file located in a different folder using the same naming convention.

i.e.

COPY L:\XMWorkspace\Projects\XXXXX-ProjectName.spcf 07066-34Henrietta.pcf

4. Scan the newly created text file for the following lines:

_SP_PROJECTNO = XXXXX
_USTN_PROJECTDESCR = Template Project
_USTN_PROJECTDATA = P:/PROJECTS XX/XXXXX-ProjectName/CAD/

and replace them with the new project info e.g. 07066-34Henrietta populates:

_SP_PROJECTNO = 07066
_USTN_PROJECTDESCR = 34Henrietta
_USTN_PROJECTDATA = P:/PROJECTS 07/07066-34Henrietta/CAD/

My batch programming is quite basic so any help and explanation along with any solution would be a million times appreciated!!!!!


Report Offensive Message For Removal

Response Number 1
Name: ghostdog
Date: July 1, 2007 at 23:30:11 Pacific
Subject: Scanning / adding numerical folder
Reply: (edit)

however basic it is, you should have started with something. Also, there are alot of resources on the web on batch that you can research on and try it out and also this forum(do a search). I know the good people here will be helping you out shortly, but the point is, what have you tried at your end?


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: July 2, 2007 at 02:32:56 Pacific
Subject: Scanning / adding numerical folder
Reply: (edit)

I'll show you how to get the proj name and increment the number.

:: pseudo code NOT real code
set lastproj=[most recent proj name]
set /p newproj=[enter name of new proj]
set prefix=!lastproj:~0,2!
set num=!lastproj:~2,3!
set /a num+=1
[The snag here is that in order to increment, you need an arithmetic SET and a number with a leading zero is taken as OCTAL, so 08 and 09 won't work. You'll need a routine to strip leading zeros.]


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: July 2, 2007 at 03:31:37 Pacific
Subject: Scanning / adding numerical folder
Reply: (edit)

Yeah, VBScript would be easier to use here. Not easy, but easier; it'll require more logic than I normally like to include with these postings. I might write this one up sometime today, after I wake up. Assuming no one else does, of course.

EDIT: But someone's going to have to explain his step 2 for me; I'm not sure what he's asking for.


Report Offensive Follow Up For Removal

Response Number 4
Name: ghostdog
Date: July 2, 2007 at 23:29:05 Pacific
Subject: Scanning / adding numerical folder
Reply: (edit)

i was going to start, but as i read further, i got more confused. guess OP needs to clarify further.


Report Offensive Follow Up For Removal

Response Number 5
Name: Razor2.3
Date: July 5, 2007 at 20:56:36 Pacific
Subject: Scanning / adding numerical folder
Reply: (edit)

Okay, I'm back at work, there have been no updates, and this has started to fall down the list. I might as well throw up something (albeit untested) for the archives:

Const sTemplateDir = "L:\XMWorkspace\Projects"
Const sTemplateCfg = "L:\XMWorkspace\Projects\XXXXX-ProjectName.spcf"
Set oFSO = CreateObject("Scripting.FileSystemObject")

'1. Request the following input while autopopulating the next available sequence number
sName = Right(DatePart("yyyy", Now), 2) & "000"
For Each d In oFSO.GetFolder(".").SubFolders
If Left(d.Name, 2) = Left(sName, 2) Then _
If StrComp(d.Name, sName) > 0 Then _
sName = Split(d.Name, "-")(0)
Next
sName = CStr(CInt(sName) + 1)
If Len(sName) < 5 Then _
sName = "0" & sName
If CInt(sName) = CInt(Right(DatePart("yyyy", Now), 2)) * 1000 + 1000 Then
Err.Description = "Too many projects"
Err.Raise 67
End If

sName = sName & "-" & Trim(InputBox("Description for project #" & sName & "?"))

'2. Copy and rename a template project folder with the user input as foldername
oFSO.CopyFolder sTemplateDir, sName, False

'3. Copy a template config text file located in a different folder using the same naming convention
'4. Scan the newly created text file for the lines...and replace them with the new project info
Set fOut = oFSO.CreateTextFile(sName & "\" & sName & ".pcf")
With oFSO.OpenTextFile(sTemplateCfg, 1)
Do Until .AtEndOfStream
sLine = .ReadLine
If Trim(sLine) <> "" Then
Select Case Split(sLine)(0)
Case "_SP_PROJECTNO"
sLine = "_SP_PROJECTNO = " & Left(sName, 5)
Case "_USTN_PROJECTDESCR"
sLine = "_USTN_PROJECTDESCR = " & Mid(sName, 6)
Case "_USTN_PROJECTDATA"
sLine = "_USTN_PROJECTDATA = " & oFSO.GetFolder(sName).Path & "\CAD\"
End Select
End If
fOut.WriteLine sLine
Loop
End With
If oFSO.FileExists(sName & "\" & oFSO.GetFileName(sTemplateCfg)) Then _
oFSO.DeleteFile sName & "\" & oFSO.GetFileName(sTemplateCfg), True



Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: July 5, 2007 at 22:03:41 Pacific
Subject: Scanning / adding numerical folder
Reply: (edit)

LOL

I set this one aside for an inspired moment, which hasn'e happened. I don't want to pour several hours into this only to be told I misread the requirement.

Let's see how OP responds to Razor2.3.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Scanning / adding numerical folder

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software