2010-11-05 93 views
1

这是批处理脚本我使用,使文件夹为新客户:让用户输入的第一个字母大写在批处理脚本

@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 

我希望能够加入能够自动大写每个单词的第一个字母。

我找到了一种方法用在它前面的空间与它的资本,它看起来像更换每一个字母做到这一点:

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

但这并不大写第一个字...

有没有想法?

回答

5

或用纯批...

@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 
) 

功能:FirstUp使用搜索在帮助字符串与VAR%的第一个字符的绝招:* X =%语法。

这会在第一次出现之前删除所有字符(因此我将所有字符加倍) 因此,首先得到单词“vox”,“VWWXXYYZZ”,然后我简单地取第一个字符%first%大写字母并在没有第一个字符后追加原始字符串的其余部分。

+0

这是一个很好的方式来做到这一点。字符串匹配不区分大小写可能会让希望看到helper = ## aAbBcC等的人感到震惊,但它的工作原理正好。 – 2010-11-10 23:01:18

0

个人而言,我已经重写它作为一个Python或VBScript:

快速/原油的VBScript代码的概念,不是特别有效,但希望读能:

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() 

最后,我建议你不要't在文件夹名称中使用逗号,它会为您节省管理员的痛苦。

Michael。

相关问题