Link to home
Start Free TrialLog in
Avatar of dba_raf_dba
dba_raf_dba

asked on

How change to upper case letter

Hi,
I've OS XP and I've under folder C: these files in lower case letters:

myfile.dwg
yourfile.dwg
cat.dwg
dog.dwg
myfile2.dwg
myfile3.dwg
myfile4.dwg
myfile5.dwg

I'd like to create a batch that change my files  to upper-case letters, like this:

MYFILE.dwg
YOURFILE.dwg
CAT.dwg
DOG.dwg
MYFILE2.dwg
MYFILE3.dwg
MYFILE4.dwg
MYFILE5.dwg

Can I change to upper case letter with batch file?

Thanks in advance!
Avatar of sirbounty
sirbounty
Flag of United States of America image

Change C:\Testing to the folder you want to work with...

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder = objFSO.GetFolder("C:\Testing\")

For Each file In objFolder.Files
  objFSO.MoveFile file.Path, UCase(Left(file.Path, InStr(file.Path, ".") - 1)) & Mid(file.Name, InStrRev(file.Name, "."))
Next

'Cleanup
Set objFolder=Nothing
Set objFSO=Nothing
From the page here:  http://dostips.com/DtCodeCmdLib.php#_toUpper there is a routine to do this which can be combined with a loop through your files and a bit of fiddling to give:

@echo off
setlocal enabledelayedexpansion
set source=c:\test
for /f "tokens=*" %%x in ('dir /b /a-d "%source%\*.dwg"') do call :toUpper %%x
goto end

:toUpper
set orig=%*
set file=%*
for %%a 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 set file=!file:%%~a!

echo rename "%source%\%orig%" "%file%"
goto end

:end
@Steve...and you wonder why I'm moving away from batch scripting to vbs...haha :)
Avatar of dba_raf_dba
dba_raf_dba

ASKER

sirbounty,
I tried (with pause) to run this batch file but I get:
C:\Testing>Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
'Dim' is not recognized as an internal or external command,
operable program or batch file.
C:\Testing>Dim objFolder: Set objFolder = objFSO.GetFolder("C:\Testing\")
'Dim' is not recognized as an internal or external command,
operable program or batch file.

and in Testing folder not change to upper case letter
Sorry - that's a vbscript - name it
Upper.vbs or something similar
If you want a pure dos batch style script, then dragon-it's version will do it for you...
@sirbounty: Amazed mem the most recently was one here for the password prompt with showing the characters and a massive batch file usin CHOICE.COM to do it, agreed VBS is THE tool for some things like this, I use it a lot for draging data out of AD using LDAP queries etc. but do like the simplicity of batch for other things...... I won't even start on SteveGTR's 100's of lines of amazing date routines but then I would use VBS for that too as two lines will often accomplish the same thing.

Steve
Yes Caudax is a wiz on complexity...wish he was around more often.
sirbounty,
I renamed your file in UPPER.vbs and seems correct on my forder test, but when I tried in my folder with 20000 files in lower case I get this error:

Script: c:\myfolder
line: 5
char: 3
Error: File already exists
code: 800A003A
Source: Microsoft VBscript runtime error

Why?




Did you catch which file it hung up on?
Try this version for displaying output...

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder = objFSO.GetFolder("C:\Testing\")

For Each file In objFolder.Files
  strFileName=UCase(Left(file.Path, InStr(file.Path, ".") - 1))
  strExtension=Mid(file.Name, InStrRev(file.Name, "."))
  wscript.echo "Renaming " & file.name & " to " & strFileName & strExtension
  objFSO.MoveFile file.Path, strFileName & strExtension
Next

'Cleanup
Set objFolder=Nothing
Set objFSO=Nothing
An idea here Sirbounty, could it be a file that is already fully uppercased and therefore it is the rename failing?  Anyway your logged version will show of course but perhaps a check for file.name <> the new filename before the rename?

Steve
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks to all,
The problem was that my path was:
c:\tomcat 5.0\filename.dwg
 The solution is:

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder = objFSO.GetFolder("C:\Tomcat 5.0\")
For Each file In objFolder.Files
 objFSO.MoveFile file.Path, UCase(Left(file.Path, Len(file.Path) - 4)) & Mid(file.Name, InStrRev(file.Name, "."))
Next
  msgbox("END")
'Cleanup
Set objFolder=Nothing
Set objFSO=Nothing
So, its fixed or not?
Wasnt sure...
my problem is fixed, but now I'd like to delete any file.zip on my folder
have I use File.Delete object?

How can I change my script to delete any file.zip on my folder c:\tomcat 5.0?

Thanks in advance!
I don't know..... people ask for a batch file and get given one but end up using VBS, it's a takeover :-)
Haha - vbs is so much cleaner and simpler...call me Benedict Arnold if you want, but I'm sold on it... :^ )

dba_raf_dba,

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder = objFSO.GetFolder("C:\Tomcat 5.0\")
For Each file In objFolder.Files
 objFSO.MoveFile file.Path, UCase(Left(file.Path, Len(file.Path) - 4)) & Mid(file.Name, InStrRev(file.Name, "."))
Next
  msgbox("END")
'Cleanup
    objFSO.DeleteFile(c:\tomcat 5.0\*.zip), True '<<<added this line
Set objFolder=Nothing
Set objFSO=Nothing

Accept sirbounty I guess :-)
Forced accept.

Computer101
EE Admin