how to loop through folders specified by text document on batch script - batch-file

I have a list of folder paths that I want to loop through and get the files and creation date and then send a email notification that these files have been uploaded to the ftp. I have got everything working but I am having trouble looping through the folders to get the files. I think it loops through the text file but by the time i get to my second loop I think it is only looping through the last path that was in the text doc as the variable was getting overwritten. I tried enclosing the second for statement with parentheses for the first for statement but did not work. Here is my code:
scanFTPCLients.bat
#echo off
setlocal EnableDelayedExpansion
cls
#pushd %~dp0
set i=0
for /F "tokens=*" %%i in (Pathlist.txt) do (
set fp=%%i
set LIST=
for /r "%fp%" %%a in (*.*) do set i=i+1
set LIST=!LIST! ---%deptClient%--- %%~na ----UPLOAD TIME---- %%~ta
)
set LIST=%LIST:~1%
IF %i% NEQ 0 (wscript "%~dp0FTPFilesUploadedNotification.vbs")
popd
Pathlist.txt
\\vavm\CINICO\Incoming
\\vavm\CIS\Incoming
\\vavm\Forcht\Incoming
\\vavm\HPC\Incoming
\\vavm\K\Incoming
\\vavm\MWEmpCC\Incoming
\\vavm\National Labor Benefits\Incoming
\\vavm\PeriSons\Incoming
\\vavm\US\Incoming
\\vavm\K\Incoming
FTPFilesNotification.vbs
dim outputArray
dim inputText
dim message
inputText = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%LIST%")
outputArray = split(inputText, " ")
for each x in outputArray
message = message & x & vbCRLF
next
Set MyEmail=CreateObject("CDO.Message")
MyEmail.Subject="Clients Imported to System"
MyEmail.From="SYSTEMFUNCTION#mrsllc.org"
MyEmail.To="rickg#gmail.com"
MyEmail.TextBody= "The Following Clients have been imported to the system: " & vbCRLF & message
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="mail.org"
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="username"
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="password"
MyEmail.Configuration.Fields.Update
MyEmail.Send
set MyEmail=nothing

For comparison, in PowerShell, it could be:
$emailSettings = #{
From = "you#example.org"
To = "you#example.org"
Subject = "Upload report"
SmtpServer = "yourmailserver"
}
$report = dir -Path #(gc pathlist.txt) | select FullName, CreationTime
Send-MailMessage #emailSettings -Body "$($report|ConvertTo-Html)" -BodyAsHtml

This shows how to loop through files in vbscript
'On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Dirname = InputBox("Enter Dir name")
'Searchterm = Inputbox("Enter search term")
ProcessFolder DirName
Sub ProcessFolder(FolderPath)
On Error Resume Next
Set fldr = fso.GetFolder(FolderPath)
Set Fls = fldr.files
For Each thing in Fls
' Set contents = thing.OpenAsTextStream
' If err.number = 0 then
' If Instr(contents.readall, searchterm) > 1 then msgbox thing.path
' Else
' err.clear
' End If
msgbox Thing.Name & " " & Thing.DateLastModified
Next
Set fldrs = fldr.subfolders
For Each thing in fldrs
ProcessFolder thing.path
Next
End Sub
To send mail
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "dc#gail.com"
emailObj.To = "dc#gail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
Set emailConfig = emailObj.Configuration
msgbox emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "YourUserName"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password1"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Done"
To read a file line by line
On Error Resume Next
Set Fso = CreateObject("Scripting.FileSystemObject")
Set File = Fso.CreateTextFile("C:\myfile.txt", True)
If err.number <> 0 then
Wscript.Echo "Error: " & err.number & " " & err.description & " from " & err.source
err.clear
wscript.exit
End If
Do Until File.AtEndOfStream
Msgbox File.readline
Loop

Changed. Not sure what you want to do about sending lines (one at a time or send all when done). If one at a time, integrate into this. If all at once at end, then send output to a temp file and send it.
#echo off
pushd %~dp0
set /A Cnt=0
for /F "tokens=*" %%i in (Pathlist.txt) do (
echo i= %%i
for /f "usebackq tokens=*" %%a in (`Dir /s /b %%i\*.*`) do (
echo %%~na - %%~ta
set /A Cnt+=1
)
)
echo(Cnt=%Cnt%
pause
popd

Related

batch find and replace

this is my problem:
on a Windows 2003 server I've a folder (c:\test), and every day an application put 3 new files on it.
1° file:
31201610181207000100000000630001
31201610181213000100000000440001
31201610181227000100000000630001
....
2° file:
31201610181214000100000000380002
31201610181234000100000009830002
31201610181344000100000000380002
...
3° file:
31201610181826000100000000580003
31201610190722000100000000580003
31201610191801000100000000580003
...
My goal is to replace ONLY the last 4 characters on each file with a .bat or .vbs script (0001 --> 0031) (0002 --> 0032) (0003 --> 0033).
I've done a .vbs file who works, but it search on all string and not on the last 4 characters.
Option Explicit
Dim objFSO, strFolder, objFolder, objFile
Dim strOldValue1, strNewValue1, strNewValue2, strOldValue2, strNewValue3,
strOldValue3, objRead, strContents, objWrite
Const ForReading = 1
Const ForWriting = 2
strFolder = "c:\test"
strOldValue1 = "0001"
strNewValue1 = "0031"
strOldValue2 = "0002"
strNewValue2 = "0032"
strOldValue3 = "0003"
strNewValue3 = "0033"
' I take the folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
' I count the file on the folder
For Each objFile In objFolder.Files
' Read file with textstream object.
Set objRead = objFSO.OpenTextFile(objFile.Path, ForReading)
' Trap error if file is empty or cannot read.
On Error Resume Next
strContents = objRead.readall
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Cannot read: " & objFile.Path
strContents = ""
End If
On Error GoTo 0
objRead.Close
' check what's is inside the folder
If (InStr(strContents, strOldValue1) > 0) Then
strContents = Replace(strContents, strOldValue1, strNewValue1)
Set objWrite = objFSO.OpenTextFile(objFile.Path, ForWriting)
objWrite.Write strContents
objWrite.Close
End If
If (InStr(strContents, strOldValue2) > 0) Then
strContents = Replace(strContents, strOldValue2, strNewValue2)
Set objWrite = objFSO.OpenTextFile(objFile.Path, ForWriting)
objWrite.Write strContents
objWrite.Close
End If
If (InStr(strContents, strOldValue3) > 0) Then
strContents = Replace(strContents, strOldValue3, strNewValue3)
Set objWrite = objFSO.OpenTextFile(objFile.Path, ForWriting)
objWrite.Write strContents
objWrite.Close
End If
next
Thanks for any help!!
Here is a short batch script, which immediately modifies all files C:\test\*.* accordingly:
for %%F in ("C:\test\*.*") do (
for /F "delims=" %%L in ('type "%%~F" ^& ^> "%%~F" rem/') do (
set "LINE=%%L"
setlocal EnableDelayedExpansion
set "LEFT=!LINE:~,-4!"
set "RIGHT=!LINE:~-4!"
if "!RIGHT!"=="0001" set "RIGHT=0031"
if "!RIGHT!"=="0002" set "RIGHT=0032"
if "!RIGHT!"=="0003" set "RIGHT=0033"
>> "%%~F" echo(!LEFT!!RIGHT!
endlocal
)
)
Using JREPL.BAT - a regular expression find/replace utility
for %%F in (c:\test\*) do call jrepl "000(?=[123]$)" "003" /f "%%F" /o -
The above looks at the end of each line for "000" before a "1", "2", or "3", and substitutes "003" for the "000".
JREPL is pure script (hybrid batch/JScript) that runs natively on any Windows machine from XP onward - No 3rd party exe file required.
Thank you very much!!!! it works!!
Also, if you're interested I've found how the make my script work:
I've to add the & VBCrlf to the variable, in this way the script will search for the value + the new line.
strOldValue1 = "0001" & VBCrlf
strNewValue1 = "0031" & VBCrlf
strOldValue2 = "0002" & VBCrlf
strNewValue2 = "0032" & VBCrlf
strOldValue3 = "0003" & VBCrlf
strNewValue3 = "0033" & VBCrlf

Making Batch file code with VBScript to work with Unicode symbols

So recently I asked for help with creating .srt subtitles. Here is the link.
I got the help and everything works fine until the videofile in the folder has unicode symbols in its name. If it does, then VBScript error appears. Question is how to make this code work correctly with Unicode symbols.
Here is the code:
#echo off&cls
::The Path of your Videos files
set "$VideoPath=C:\FolderwithVideos"
::If you want your Code in this BAT remove the REMs Below :
rem dir "%$VideoPath%" /O:S /b /-p /o:gn > "C:\result.txt"
rem call replacer.bat result.txt ".mp4" ""
setlocal enabledelayedexpansion
set /a $Count=1
set "$Timer=00:00:00"
(for /f "delims=" %%a in (result.txt) do (
call:getVideolength "%%a.mp4"
for /f "delims=" %%x in ('cscript //nologo getvideolength.vbs') do (
call:SumTime !$Timer! %%x
for /f "delims=" %%y in ('cscript //nologo SumTime.vbs') do set "$NewTimer=%%y"
echo !$Count!
echo !$Timer!,000 --^> !$NewTimer!,000
echo %%a
Set $Timer=!$NewTimer!
)
set /a $Count+=1
echo.
))>Output.srt
echo Done !!!
type Output.srt
pause
exit/b
:GetVideoLength
(echo dim objShell
echo dim objFolder
echo dim objFolderItem
echo set objShell = CreateObject("shell.application"^)
echo set objFolder = objShell.NameSpace("%$videoPath%"^)
echo set objFolderItem = objFolder.ParseName(%1^)
echo dim objInfo
echo objInfo = objFolder.GetDetailsOf(objFolderItem, 27^)
echo wscript.echo objinfo)>GetVideoLength.vbs
exit/b
:SumTime
echo wscript.echo FormatDateTime(CDate("%1"^) + CDate("%2"^),3^) >SumTime.vbs
exit/b
After reviewing the previous question I merged all the code and logic into one unicode safe VBScript file.
Option Explicit
Const adUnsignedBigInt = 21
Const adVarWChar = 202
Const adVarChar = 200
Dim VideoDir
VideoDir = "C:\FolderwithVideos"
'or from a script argument when called like : cscript script.vbs "C:\FolderwithVideos"
'VideoDir = WScript.Arguments(0)
Const adSaveCreateOverWrite = 2
Const adCRLF = -1
Const adWriteLine = 1
Dim ShellApp
Set ShellApp = CreateObject("Shell.Application")
Dim Fso
Set Fso = CreateObject("Scripting.Filesystemobject")
Dim VideoExts
Set VideoExts = CreateObject("scripting.dictionary")
VideoExts.CompareMode = vbTextCompare
VideoExts.Add "mp4", Null
'add more extensions if you need
'VideoExts.Add "srt", Null
'VideoExts.Add "mkv", Null
Dim SrtStream
Set SrtStream = CreateObject("Adodb.Stream")
SrtStream.Charset = "utf-8"
SrtStream.Open
Dim Folder, IFolderItem, VideoCount, OldDuration, NewDuration, FileExtension, SrtPath, RsSorted
Set RsSorted = CreateObject("Adodb.Recordset")
RsSorted.Fields.Append "Name", adVarWChar, 255
RsSorted.Fields.Append "Size", adUnsignedBigInt
RsSorted.Fields.Append "Duration", adVarChar, 8
RsSorted.Open
NewDuration = TimeSerial(0,0,0)
Set Folder = ShellApp.NameSpace(VideoDir)
For Each IFolderItem In Folder.Items
FileExtension = Fso.GetExtensionName(IFolderItem.Name)
If VideoExts.Exists(FileExtension) Then
RsSorted.AddNew Array("Name", "Size", "Duration"), Array(IFolderItem.Name, IFolderItem.Size, Folder.GetDetailsOf(IFolderItem, 27))
End If
Next
RsSorted.UpdateBatch
RsSorted.Sort = "Size, Name"
If Not RsSorted.BOF Then RsSorted.MoveFirst
While Not RsSorted.EOF And Not RsSorted.BOF
FileExtension = Fso.GetExtensionName(RsSorted("Name").Value)
VideoCount = VideoCount + 1
OldDuration = NewDuration
NewDuration = OldDuration + CDate(RsSorted("Duration").Value)
SrtStream.WriteText VideoCount, adWriteLine
SrtStream.WriteText OldDuration & ",001 --> " & NewDuration & ",000", adWriteLine
SrtStream.WriteText Left(RsSorted("Name").Value, Len(RsSorted("Name").Value) - (Len(FileExtension) + 1)), adWriteLine
SrtStream.WriteText "", adWriteLine
RsSorted.MoveNext
Wend
SrtPath = Fso.BuildPath(VideoDir, "Output.srt")
SrtStream.SaveToFile SrtPath, adSaveCreateOverWrite
SrtStream.Close
WScript.Echo "Done!"
WScript.Echo SrtPath

windows ".lnk" shortcuts and batches don't mix

I have a batch file which is used by dragging a folder containing .mp3s into the batch.
#echo off
cd %~dp0
setlocal enabledelayedexpansion enableextensions
set FLDR="%1"
if not defined FLDR ( echo Drag a folder to the batch to play its contents.
pause
goto:EOF )
for %%x in (%FLDR%\*.mp3) do set "MP3=!MP3! "%%x""
mp3player %MP3%
pause
It works fine with actual folders, but when dragging shortcuts, the variable %FLDR% ends up as "c:\link location\folder.lnk" instead of the actual folder location.
I have no idea how to get around this.
Here is a way to get the target using a little hybrid VBS/Batch file function.
#echo off
setlocal
Call :GetTarget "%~1" tgt
echo %tgt%
pause
exit /b
:GetTarget
#echo off & setlocal
set gt=%temp%\_.vbs
echo set WshShell = WScript.CreateObject("WScript.Shell")>%gt%
echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>%gt%
echo wscript.Echo Lnk.TargetPath>>%gt%
set script=cscript //nologo %gt%
For /f "delims=" %%a in ( '%script% "%~1"' ) do set target=%%a
del %gt%
endlocal & set %~2=%target%
exit /b
HYBRID SCRIPT! No silly little temporary files.
::'<SUB>#echo off
::'<SUB>set shortcut=%~1
::'<SUB>if not defined shortcut goto 'usage
::'<SUB>if not %shortcut:~-4%==.lnk (if not %shortcut:~-4%==.url (set errorlevel=1
::'<SUB>goto 'usage ))
::'<SUB>if not exist %shortcut% (echo Error: Nonexistent shortcut
::'<SUB>set errorlevel=1
::'<SUB>goto:EOF )
::'<SUB>setlocal
::'<SUB>for /f "delims=" %%T in ('cscript //nologo //e:vbs %~nx0 "%shortcut%"') do set thing=%%T
::'<SUB>endlocal & set shortcut=%thing%
::'<SUB>goto:EOF
:'usage
::'<SUB>echo command-line shortcut redirect utility
::'<SUB>echo Usage: shortcut [file.lnk ^| file.url]
::'<SUB>echo The resulting link will be output to the %%shortcut%% variable.
::'<SUB>goto:EOF
set WshShell = WScript.CreateObject("WScript.Shell")
set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))
wscript.Echo Lnk.TargetPath
Where <SUB> indicates the substitute character.
UPDATE: I found a much fully vbscript solution over at Wayne's World of IT, and modified it slightly to suit my needs:
If WScript.Arguments.UnNamed.Count = 1 Then
strShortcut = WScript.Arguments.UnNamed(0)
Else
WScript.Echo "Please supply the name of an lnk file or directory to read, eg c:\test.lnk or c:\shortcuts"
WScript.Quit(1)
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strShortCut) Then
Set objFolder = objFSO.getFolder(strShortcut)
For Each objfile in objFolder.Files
If objfile.type = "Shortcut" Then
Call Readshortcut(objFile.Path, strProperties)
dtmCreationDate = objFile.DateCreated
WScript.Echo dtmCreationDate & "," & strProperties
End If
Next
ElseIf objFSO.FileExists(strShortCut) Then
Call Readshortcut(strShortcut, strProperties)
WScript.Echo strProperties
Else
WScript.Echo "Error: Could not read '" & strShortcut & "'"
WScript.Quit(2)
End If
Set objFSO = Nothing
Function Readshortcut(ByRef strShortcut, ByRef strProperties)
set objWshShell = WScript.CreateObject("WScript.Shell")
set objShellLink = objWshShell.CreateShortcut(strShortcut)
strProperties = objShellLink.TargetPath & " " & objShellLink.Arguments
Set objShellLink = Nothing
Set objWshshell = Nothing
End Function

compare two files using batch script

I've two files
file 1:
PROCESS_NAME
wf_1
wf_2
wf_3
file 2:
wf_1 - [Running]
wf_2 - [Succeeded]
wf_2 - [Succeeded]
So now I need to compare the above two files and have to remove the names in file1 for which the status in file2 is [Succeeded]. Struggling for hte past 3 days.
Result should be
file 1:
wf_1
Appreciate any help.
Here you go
#echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (file1.txt) do (
for /f "skip=1 tokens=*" %%b in ('find "[Succeeded]" file2.txt') do (
set check=%%b
set check=!check: - [Succeeded]=!
if "%%a"=="!check!" set bool=true
)
if not "!bool!"=="true" echo %%a >>new.txt
)
del file1.txt /f /q
ren new.txt file1.txt
Just replace file1.txt and file2.txt with your actual file names.
Const ForReading = 1
Const TextCompare = 1
Dim File1, File2, OutputFile
File1 = "D:\1t\test1\ddir11.txt"
File2 = "D:\1t\test1\ddir12.txt"
OutputFile = "D:\1t\test1\outfile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
If ObjFSO.FileExists(File1) Then
Dim objFile1 : Set objFile1 = objFSO.OpenTextFile(File1, ForReading)
Else
WScript.Quit
End If
' Dictionary object for reference file.
Dim RefDict : Set RefDict = CreateObject("Scripting.Dictionary")
RefDict.CompareMode = TextCompare
Dim StrLine, SearchLine, strNotFound
' Read reference file into dictionary object.
Do Until objFile1.AtEndOfStream
StrLine = Trim(objFile1.ReadLine)
'MsgBox (StrLine)
if Not RefDict.Exists(StrLine) Then
RefDict.Add StrLine, "1"
End If
Loop
Dim a,s,i
a = RefDict.Keys
'read dictionary....
'For i = 0 To RefDict.Count -1 ' Iterate the array.
' s = s & a(i) & "<BR>" ' Create return string.
'Next
objFile1.Close
' File that may have more or less lines.
If ObjFSO.FileExists(File2) Then
Dim objFile2 : Set objFile2 = objFSO.OpenTextFile(File2, ForReading)
Else
WScript.Quit
End If
' Search 2nd file with reference file.
Do Until objFile2.AtEndOfStream
SearchLine = Trim(objFile2.ReadLine)
If Not RefDict.Exists(SearchLine) Then
If IsEmpty(strNotFound) Then
strNotFound = SearchLine
Else
strNotFound = strNotFound & vbCrlf & SearchLine
End If
End If
Loop
objFile2.Close
If IsEmpty(strNotFound) or strNotFound = "" Then
End If
Dim objFile3 : Set objFile3 = objFSO.CreateTextFile(OutputFile, True)
MsgBox ("str:" & strNotFound)
objFile3.WriteLine strNotFound
objFile3.Close

Make the first letter of user input a capital in a batch script

This is the batch script I use to make the folders for a new client:
#ECHO OFF
SET /p clientLast=Enter Client's Last Name:
SET /p clientFirst=Enter Client's First Name:
ECHO Making Folders...
MKDIR "%clientLast%, %clientFirst%"
MKDIR "%clientLast%, %clientFirst%"\Budget
MKDIR "%clientLast%, %clientFirst%"\"Business Registration"
MKDIR "%clientLast%, %clientFirst%"\Correspondence
MKDIR "%clientLast%, %clientFirst%"\"Financial Info"
MKDIR "%clientLast%, %clientFirst%"\Forms
MKDIR "%clientLast%, %clientFirst%"\Illustrations
MKDIR "%clientLast%, %clientFirst%"\"Loans & Investments"
MKDIR "%clientLast%, %clientFirst%"\"Personal Info"
MKDIR "%clientLast%, %clientFirst%"\Recommendations
MKDIR "%clientLast%, %clientFirst%"\"Tax Misc"
TREE "%clientLast%, %clientFirst%"
ECHO DONE~~~~~~~~~~~~~~~
PAUSE
I want to be able to add the ability to automatically uppercase the first letter of each word.
I found a way to do it by replacing every letter with a space in front of it with it's capital, which looks something like:
FOR %%i IN ("a=A" " b= B" " c= C" " d= D" " e= E" " f= F" " g= G" " h= H" " i= I" " j= J" " k= K" " l= L" " m= M" " n= N" " o= O" " p= P" " q= Q" " r= R" " s= S" " t= T" " u= U" " v= V" " w= W" " x= X" " y= Y" " z= Z") DO CALL SET "%1=%%%1:%%~i%%"
But this does not capitalize the first word...
Any ideas?
Or with pure batch...
#echo off
setlocal EnableDelayedExpansion
call :FirstUp result hello
echo !result!
call :FirstUp result abc
echo !result!
call :FirstUp result zynx
echo !result!
goto :eof
:FirstUp
setlocal EnableDelayedExpansion
set "temp=%~2"
set "helper=##AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ"
set "first=!helper:*%temp:~0,1%=!"
set "first=!first:~0,1!"
if "!first!"=="#" set "first=!temp:~0,1!"
set "temp=!first!!temp:~1!"
(
endlocal
set "result=%temp%"
goto :eof
)
The function :FirstUp use the trick of searching for the first character in the helper string with the %var:*x=% syntax.
This removes all chars before the first occurrence (therefore I double all chars)
So, in first you got for the word "vox", "VWWXXYYZZ", then I simply take the first char of %first% to get the capital and append the rest of the original string without after the first char.
Personally I'd rewrite it as a python or vbscript:
Quick / crude vbscript concept code, not particularly efficient but hopefully read-able:
Function MakeDirectories (strRootFolder, strParentFolder, strArrayFolderNames)
on error resume next
err.clear
Set objFSO = CreateObject("Scripting.FileSystemObject")
strParentFolder = strRootFolder & "\" & strParentFolder
if not objFSO.FolderExists(strParentFolder) then
objFSO.CreateFolder(strParentFolder)
end if
if err.number then
MakeDirectories = false
exit function
end if
dim strNewFolder
for each strfolderName in strArrayFolderNames
strNewFolder = strParentFolder & "\" & ProperNames(strFolderName)
if not objFSO.FolderExists(strNewFolder) then
objFSO.CreateFolder(strNewFolder)
end if
next
if err.number then
MakeDirectories = false
else
MakeDirectories = True
end if
End function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function Proper ( strText )
Proper = ucase(left(strText,1)) & lcase(mid(strText,2))
end function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function ProperNames ( strText )
if instr(strText," ") > 0 then
dim temp, i
temp = split(strText, " ")
for i = lbound(temp) to ubound(temp)
temp(i) = Proper(temp(i))
next
ProperNames = join(temp, " ")
else
ProperNames = Proper(strText)
end if
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Main ( )
dim strLastName, strFirstName
strLastName = InputBox("Please enter the client's last name:")
if strLastName = "" then exit sub
strFirstName = InputBox("Please enter the client's first name:")
if strLastName = "" then exit sub
'' a better alternative might be to put the desired folder
'' into a text file and have the program read said data
dim strArrayFolderNames(9)
strArrayFolderNames(0) = "Budget"
strArrayFolderNames(1) = "Business Registration"
strArrayFolderNames(2) = "Correspondence"
strArrayFolderNames(3) = "Financial Info"
strArrayFolderNames(4) = "Forms"
strArrayFolderNames(5) = "Illustrations"
strArrayFolderNames(6) = "Loans & Investments"
strArrayFolderNames(7) = "Personal Info"
strArrayFolderNames(8) = "Recommendations"
strArrayFolderNames(9) = "Tax Misc"
dim strDelimeter, strRootFolder, strParentFolder
strDelimeter = "-" '' I suggest avoiding the use of ","
strRootFolder = "C:\docs\temp"
strParentFolder = Proper(strLastName) & strDelimeter & Proper(strFirstName)
If MakeDirectories(strRootFolder, strParentFolder, strArrayFolderNames) then
wscript.echo ("Folders all made.")
else
wscript.echo ("Error: one or more folders was not created.")
end if
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Main ()
Finally, I suggest you don't use commas in folder names, it will save you admin grief down the road.
Michael.

Resources