Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows 2000 Batch File 3

Status
Not open for further replies.

edemiere

MIS
May 13, 2003
483
US
Hello everyone. I am a very experienced computer user, however I have a problem now that I have never had to tackle.

I have a bunch of files in a directory like this:

xyz0101a.dwg

I need to convert the files to all uppercase. I have easily made the files look like this:

XYZ0101a.dwg

The last letter before the .dwg is causing me grief (as it can be any letter in the alphabet).

Is anyone an advanced batch script writer that can help me create the necessary batch file to convert all letters to uppercase in a filename?

Thanks in advance for any insight anyone can provide.

Cheers!

 

That might have been useful, but I can NOT permitted to use any software not authorized by my company, hence why I am seeking a batch process that I will write to perform my desired action. [bigsmile]

Thanks for the reply though!

Cheers!

 
The problem is that there isn't a batch command for upper/lower case .
You will have to cache all the filenames and do a ren
on them .
 
You might want to try this (WSH required):

Save the file with JS for the extension

------------
var oFSO = new ActiveXObject("Scripting.FileSystemObject")
cSrc = "D:\\Temp"
oFolder = oFSO.GetFolder(cSrc)
if (oFolder.Files.Count > 0)
{
var oFiles = new Enumerator(oFolder.Files)
for (; !oFiles.atEnd(); oFiles.moveNext())
{
var cFile = oFiles.item().Path.toUpperCase()

// Remove the remarks to see the filename display
// on MessageBox
// WScript.Echo(cFilename)

oFSO.MoveFile(cFile, cFile)
}
oFiles = null
}

oFolder = null
oFSO = null
-----------------

Regards

-- AirCon --
 
Let hope that the boss approves the wsh file then.
SYAR
 
Yep, you are right. Some people doesn't want it exist in their computer

-- AirCon --
 

Yeah, what I was looking for was something that would cache in variables and then do a test condition based on alpha character and then ren it to the upper one.

I know, cumbersome, but I have little other choice and sitting here hitting F2 to manually edit each file (I have done about 1000 this way, but have about 42,000 more files to do) is just not cutting it.

Thanks in advance for any inputs you guys are giving.

As for the WSH thing, well, like I said, I have no permissions and authorization to do anything to the PC's being used, consequently this will have to be either something vbscript that windows can run native, or something setup in a DOS Windows batch file.

Thanks guys! [smile]

 
If you can run vbscript, I suspect that WSH is also installed in that computer. They both Windows Script.
So try it first.

-- AirCon --
 
BATCH:

Cache filenames dir /B >tempdir.txt

If cashed filenames to a temp file and use ren for each file
substituting a ? will not touch the char.
E.g
Ren xyz0101a.dwg XYZ0101?.??? result= XYZ0101a.dwg

SYAR
 
AirCon
Hmm, the .js didn't work, gave me an error about the path not being found, so I changed it to reflect the path that i was working in, but still no go.

The full error looks like this:

Script: e:\storage\ztemp\up.js
Line: 3
Char: 1
Error: Path not found
Code: 800A004C
Source: Microsoft JScript runtime error

SYAR2003

Let's make sure we are on the same page here.

I have a directory with a LOT of files.

xyz0101a.dwg

I have a batch file that renames them all to XYZ0101a.dwg

I need to convert that last letter before the .dwg to a capital letter. So, I am wanting:

XYZ0101A.dwg

Maybe you said it but I just didn't get it, though I did read it several times. Let me know if I am missing something here. [thumbsup]

Thanks you two, I appreciate your time!

Cheers!
 
It means that you have WSH.

Now, how do you change the path name? are you using single backslash or double backslash?

You have to use double backslash -> \
But I didn't read your first message carefully.
So here is to go:

---------------
var oFSO = new ActiveXObject("Scripting.FileSystemObject")
// Change this to your working folder
// And remember to use double backslash
cSrc = "D:\\Temp"
oFolder = oFSO.GetFolder(cSrc)
if (oFolder.Files.Count > 0)
{
var oFiles = new Enumerator(oFolder.Files)
for (; !oFiles.atEnd(); oFiles.moveNext())
{
var cFile = oFiles.item().Path.toLowerCase()
var nLen = cFile.length
cFilename = cFile.substr(0, nLen-3)
cFilename = cFilename.toUpperCase() + cFile.substr(nLen-3, 3)
oFSO.MoveFile(cFilename, cFilename)
}
oFiles = null
}

oFolder = null
oFSO = null
-------------------

Regards

-- AirCon --
 
AirCon

Ok, that works great, however....

Now level 2 of my problem is I'd like to be able to run this in varying directories, which I guess is why I was looking for a DOS batch file to begin with since I am navigating directories in a DOS window.

Now that you have given me an alternative, I suppose I should describe in length what I am being asked to do.

I have a server that appears as a mapped drive on my system for storing our AutoCAD drawing files. The main folder is the city, and the subfolders are the sites in those cities. Each site folder has subfolders depending on the type of drawing it contains (rack elevation, floor plan, etc). These folders have a LOT of files contained therein and my task is a 2 phase task: (1) Edit each file manually and make sure it doesn't contain errors, etc and (2) Standardizing the name conventions of all the files in each folder. (i.e. make them all uppercase names with a lowercase extention).

So, as an example, there is an ABC folder and it contains files abc0101a.dwg abc0201p.dwg abc0306c.dwg (so on and so forth). I run a batch file called abc.bat and it makes the files ABC0101a.dwg ABC0201p.dwg ABC0306c.dwg which is close to what I want. After I run that batch file I have to manually edit each filename and fix that last character before the .dwg to a capital letter so I can move on. It's become so cumbersome to my progress, I am only like 1000 files along after spending this whole week doing them.

So, I have a lot of copy and pasting I do to move files around after I check them so pasting that .js file into each directory is almost as cumbersome so I am trying to find an all encompassing solution that will handle all my renaming needs in one fail swoop.

I hope that wasn't too confusing!

Thanks again...
 
Well,

I'm not exactly sure, but give this a try. This will recursive into all subfolders from the first folder you specify. So if you specify from root directory it will change the entire file on your disk (it may take a while tho). Hope it works :)

----------------
var oFSO = new ActiveXObject("Scripting.FileSystemObject")
// Change to your Root working folder, e.g.: "C:\\"
cSrc = "C:\\Temp"
oFolders = oFSO.GetFolder(cSrc)

if (oFolders.Files.Count > 0)
{
ChangeFilename(oFolders)
}

if (oFolders.SubFolders.Count > 0)
GetFolder(oFolders)

oFolders = null
oFSO = null


function GetFolder(oFolder)
{
var oFld = new Enumerator(oFolder.SubFolders)
for (; !oFld.atEnd(); oFld.moveNext())
{
ChangeFilename(oFld.item())
if (oFld.item().SubFolders.Count > 0)
GetFolder(oFld.item())
}
oFld = null
}


function ChangeFilename(oFolder)
{
var oFiles = new Enumerator(oFolder.Files)
for (; !oFiles.atEnd(); oFiles.moveNext())
{
var cFile = oFiles.item().Path.toLowerCase()
var nLen = cFile.length
cFilename = cFile.substr(0, nLen-3)
cFilename = cFilename.toUpperCase() + cFile.substr(nLen-3, 3)
oFSO.MoveFile(cFilename, cFilename)
}
oFiles = null
}
-----------------

Regards

-- AirCon --
 
Why don't you post your existing abc.bat file here? We can have a look then and maybe modify.

Or, as SYAR posted according to your first post

Ren xyz0101a.dwg XYZ0101?.??? result= XYZ0101a.dwg
Would then become:
Ren ???????a.dwg ???????A.dwg result= XYZ0101A.dwg


Marc
If 'something' 'somewhere' gives 'some' error, expect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
 

AirCon

Hey bud! That script works GREAT (mostly)!

Thanks so much.

I am only experiencing 2 problems and only 1 of which I think you might be able to correct.

I will tell you both problems just in case you have a trick up your sleeve:

1. When I copy to the network drive and run it nothing happens. Yes, the drive is mapped and yes I update the file with the proper drive path.

2. I copied 58 directories to my hard drive, ran the script and it works flawless until it hits the 15th directory in the root tree. At that point none of the files get changed.

Anyway you could give me a progress indicator or some output file so maybe I can see any errors encountered?

Thanks much!

Cheers!
 

AirCon

Ok, I just ran it again and now it seems to have worked past the 15th directory. Hmm, now I am baffled.

I guess I will keep testing, though a progress indicator would still be bomb so at least I would know when its done. Perhaps I started moving stuff back too quickly or something.

Each directory I am copying over has on average 15 subdirectories and over 5000 files (in total).

Many thanks again for your time and effort though, at least I am making some solid headway and I might perhaps have them all done today! [2thumbsup]

Cheers!

 

AirCon

Ok, I am about to conduct another test with the script on my next site directory.

It is 13,834 Files and 1,885 Folders for this particular site.

I will let you know how it works out.

Cheers!

 

Ok, that must be what it was. I watched my Windows Task Manager for wscript.exe to disappear and it appears as though everything got changed this time, I guess I was just too hasty at trying to move it back.

Many thanks again for the help, it appears as though my problem is solved!

Stars for everyone that helped! :)

Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top