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 Shaun E 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!

 
Hi edemiere,
Sorry, a little late

it appears as though my problem is solved!

So the last status is, it works, right ?
Well, you worked so hard. I am glad if it works for you. Also I don't have to change the code again :-D

Regards

-- AirCon --
 
On the subject of batch files, I was familiar with the old DOS batch files but I didnt know there was an equivalent in windows. Is this correct?
How do you run them without something to compile them like VB or C?
Also is there a handy reference of the format of these commands is like there used to be in the old DOS handbooks?
 
you just run them as before by double click on a .bat file or manually in a command prompt.
the same 'handy' format is help, but since you are familiar with them, they a basically 99% the same.
just type any command /? and you will get the full options.

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!
 
Hi tedsmith,

How do you run them without something to compile them like VB or C?

Because windows has a tools to run the script, and that is Windows Scripting Host (WSH). The runtime is WScript.exe. So it has to be in the system.

The full documentation is here:

Regards

-- AirCon --
 

Hi again guys, but back to touching on this topic, the DOS approach I was originally looking at would come out to look and work just like this:

----------Being Batch File----------
Echo.
If not exist %~f1.\*.dwg (Echo No .dwg files found in %~f1 & GoTo :EOF)

Echo Converting to upcase the .dwg files in %~f1
Echo.
For /F "tokens=1 delims=." %%A in ('Command /C Dir /B %~f1.\*.dwg') Do (
Echo %%A.dwg
Ren %~f1.\%%A.dwg %%A.dwg)
Echo.
Echo Processing completed
----------End Batch File----------

This is how you'd get it done in DOS, which was my original intent, though it's a moot point for me now, I thought I'd post the solution here. [bigsmile]

Thanks again!

 
Ah, that is initially why I asked you to post your bat file on November 20.
Good you found it!
 
marcs41

Back then I didn't have one that worked, the only thing I could do is make it uppercase the first few letters and then lowercase the extention of the name, but not uppercase the last letter before the extention. [bigsmile]

But that last .bat posting would take care of all that.

Cheers!

 
I think you misunderstood.
I meant to post what you HAD (working or not), so we could maybe correct it.
 

Aircon

Let me know if you are still following this thread. You know, if you put out one fire, management likes to start 2 more to test response time or something, lol.

Anyway, I have a new problem I need to address and I think we might even be better off going back and forth in email.

Let me know if you have some time to think about a problem I gotta get tackled. I am not really a programmer or anything even remotely close, but I seem to be the catchall boy or something. [bigsmile]

Thanks!

 
Hi edemiere,

Yes I'm still following this thread. So what you have in mind? :-D

Regards

-- AirCon --
 

Ok, let me try to explain this as best as I can.

I have a series of folders that follow this sequence:

SITENAME\SITENUMBER\TYPEOFDRAWING

So, for example:

G:\NETWORK\DRAWINGS\CHICAGO\001\AMS
G:\NETWORK\DRAWINGS\CHICAGO\001\EFL
G:\NETWORK\DRAWINGS\CHICAGO\001\FPL

etc...

These are the directories that I renamed all the files in with the last batch file you did.

Now, in each of the type of drawing folders there are multiple "revisions" of the same drawing. The naming convention of those drawings are as follows:

EFL0101A.dwg <-- this is the initial release name

As the drawing faces MORE revisions the letter gets increased by one. So, if we modified THIS drawing it would become:

EFL0101B.dwg

Now, as time and revisions progress past the revision letter of Z the drawing would become:

EFL0102A.dwg

Hope you are still with me. So, for example in the EFL directory I might have the following files in there:

EFL0101A.dwg
EFL0101B.dwg
EFL0101C.dwg
EFL0201A.dwg
EFL0301A.dwg
EFL0301B.dwg
EFL0301C.dwg
EFL0301D.dwg

I need to magically somehow, using some finesse method to have this script check the directories that exist and always copy the latest revision to my local hard drive to be put on to a CD at a later time.

So, from the directory listing I gave you in the EFL directory, on my harddrive I would like to see the following occur after I run the script:

E:\ZTEMP\CHICAGO\001\EFL

And inside that directory I would (ideally) like to see:

EFL0101C.dwg
EFL0201A.dwg
EFL0301D.dwg

Basically, the script needs to check the contents of all subfolders, check for the highest increment of any given rev and then copy it to my hard drive. The files I listed above that I'd like to see copied to my harddrive are 3 unique and distinct drawings. I hope you see the pattern I was trying to establish. Some directories might have 100 files of varying revision numbers and the batch file or script would need to know and understand how the increment works.

Confused yet? lol It's a mess and a rather large headache for me.

Keep in mind that I'd also need this to repeat for a certain subset subdirectories that we could &quot;hard code&quot; for it to sweep through. I can tell you what the subfolder names I want to check are because there are folders there that we don't care about. So, we ONLY want to check certain folder names to make sure they exist and if they do then copy the latest revision of each drawing to my harddrive (and while copying, create the SAME directory tree that its copying from). So, if the EFL directory is empty when it checks it (because it will always exist) it won't copy anything and it won't make an EFL directory on my harddrive. And of course, it should sweep all 900 sites that exist (somewhere on the order of 4000 folder and 55,000 files or something).

I hope this makes sense. Let me know if you need any clarifications. [thumbsup]

Cheers!

 
Edemiere,

Just thought of a way of doing it, but it needs a relational database engine. Do you by any chance have a copy of MS Access available to use?

Basically, it would parse the tree and insert the filenames, then select the Max (filename) grouped by on the
filename - rather than the path.
Then you would have a list of files in a query, and it would be a simple matter to trigger a copy of them to an equivalent folder on the c: drive.

Although I suggest MS access (simply because that's what I know), any desktop relational database engine with programming facilities would do, so if you have Paradox, Dbase or something else, a competent programmer could knock something up in there.

John
 
Edemiere,

I need more time to think about that, if you want to go by script. Because I only use script for small things. So i'm not really into script either :-D

But I think I can find the workaround for it. Just need more time to read your explanation carefully (I'm not a native English). Maybe I also need to ask few more question to clarify.

BTW, I agree with John. It's not that difficult if we do this with programming language. But it will be off-topic for this forum.

Now, if that's ok with members here, we can go in this forum. If not maybe we better go through email as you already suggested. So please post your email (just in case :-D )

Regards

-- AirCon --
 
Ok, I think no one have any objection :)

I want to clarify first. I tested with a folder like this:

D:\Tmp\EFL
Where:
D:\ -> Source DriveTmp\ -> SiteName\SiteNumberEFL\ -> TypeOfDrawing
In the folder I have this file (unsorted):
EFL0101E.dwg
EFL0101B.dwg
EFL0102A.dwg
EFL0101F.dwg
EFL0101H.dwg
EFL0101Y.dwg
EFL0201C.dwg
EFL0201B.dwg
EFL0201T.dwg
EFL0201G.dwg

The files that needs to be copy is:
1. EFL0102A.dwg
2. EFL0201T.dwg

And it will be copy to the target folder:
E:\ -> Target DriveTmp\ -> SiteName\SiteNumberEFL\ -> TypeOfDrawing
Also, you want the &quot;EFL\&quot; folder changeable.

Is that all correct ?


-- AirCon --
 

AirCon

Yes, that is all correct.

The only question I have is what do you mean by:

Also, you want the &quot;EFL\&quot; folder changeable.?

Not sure exactly what you mean by that.

Lastly, to remind you, there will be multiple folders that it will search through, EFL is just 1 of those folders.

So far, you are right on though. [2thumbsup]

Cheers!

 
Edemiere,

I am sorry. I just have the time to login by now.
Okay, so it is correct. Let's try this first. Watch out for wordwrap

[ignore]------------
var oFSO = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;)
cSrcDrive = &quot;D:\\&quot; // Source drive
cDestDrive = &quot;E:\\&quot; // Target drive
cFolder = &quot;Tmp\\&quot; // SiteName\SiteNumber
cType = &quot;EFL\\&quot; // TypeOfDrawing
cSource = cSrcDrive + cFolder + cType
cTarget = cDestDrive + cFolder + cType
oFolders = oFSO.GetFolder(cSource)

if (oFolders.Files.Count > 0)
CopyFilename(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())
{
CopyFilename(oFld.item())
if (oFld.item().SubFolders.Count > 0)
GetFolder(oFld.item())
}
oFld = null
}


function CopyFilename(oFolder)
{
var oFiles = new Enumerator(oFolder.Files)
nCount = oFolder.Files.Count
var aFiles = new Array(nCount)
var aFileToCopy = new Array()
for (i = 0; i < nCount; i++)
{
aFiles = oFiles.item().Name
oFiles.moveNext()
}

aFiles = aFiles.sort()
cFile = aFiles[0]
j = 0
for (i=0; i < nCount; i++)
{
nLen = cFile.length
if (cFile.substr(0, nLen-7) != aFiles.substr(0, nLen-7))
{
cFile = aFiles
j++
}
aFileToCopy[j] = aFiles
}

if (!oFSO.FolderExists(cDestDrive+cFolder))
oFSO.CreateFolder(cDestDrive+cFolder)

if (!oFSO.FolderExists(cDestDrive+cFolder+cType))
oFSO.CreateFolder(cDestDrive+cFolder+cType)

for (i=0; i < aFileToCopy.length; i++)
oFSO.CopyFile(cSource+aFileToCopy, cTarget+aFileToCopy)

oFiles = null
aFiles = null
aFileToCopy = null
}
-----------------[/ignore]

Let me know the results
Regards

-- AirCon --
 
AirCon

Ok, that works great, however, it seems as though the destination path must exist.

What I was aiming for is that as it wants to copy the files that it would basically replicate the directory structure it is copying from. You follow me?

Also, I want to put this script in a folder:

G:\CMH_NS Groups\DWGS

When I execute the script it will ONLY look at the SITE NAME folders which are named:

AKRN, ASHT, CLEV, CLMB, CLTN, CNCN, CNTN, DYTN, HMTN, HNCC, LORN, MBLS, MNFD, MRCR, MROW, SNDS, SPFD

Then inside those folders there are folders carrying names:

001, 002, 003, etc (but not necessarily sequential, there might be some numbers missing in the sequence).

Then inside those folders there are a series of folders carrying names:

AMS, CLL, CRD, DFA, EFL, FFA, FPA, FPL, IOP, NFA, PGS

Ok, I hope you are with me still, lol.

In closing, your batch file worked after I made the following change the the variable section:

--------------------
cSrcDrive = &quot;G:\\CMH_NS Groups\\DWGS\\&quot; // Source drive
cDestDrive = &quot;E:\\ZTEMP\\&quot; // Target drive
cFolder = &quot;AKRN\\026\\&quot; // SiteName\SiteNumber
cType = &quot;EFL\\&quot; // TypeOfDrawing
--------------------

I also had to create E:\ZTEMP\AKRN\026 for it to work. Once I made the destination path, it did create the EFL directory and put the correct files inside it.

Cheers!

 
Ohh.. I think I got it now. Well, in that case you need to break down the folder one by one so it can create the exact folder like the source.

In the mean time give me some time to adjust the code :-D
Regards

-- AirCon --
 
Okay here it is. I think you got it all here basically, so I hope you can work it out :)

[ignore]----------------
var oFSO = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;)
// Source Drive + working folder, e.g.: &quot;G:\CMH_NS Groups\DWGS&quot;
cSrcDrive = &quot;D:\\Tmp&quot;
// Target Drive + working folder, e.g.: &quot;E:\CMH_NS Groups\DWGS&quot;
cDestDrive = &quot;E:\\Tmp&quot; // must exist or create it first
oFolders = oFSO.GetFolder(cSrcDrive)

if (oFolders.Files.Count > 0)
CopyFilename(oFolders)

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

oFolders = null
oFSO = null


function GetFolder(oFolder, cTarget)
{
var oFld = new Enumerator(oFolder.SubFolders)
for (; !oFld.atEnd(); oFld.moveNext())
{
cTargetFolder = cTarget + &quot;\\&quot; + oFld.item().Name
if (oFld.item().Files.Count > 0)
{
if (!oFSO.FolderExists(cTargetFolder))
oFSO.CreateFolder(cTargetFolder)
CopyFilename(oFld.item(), cTargetFolder)
}
if (oFld.item().SubFolders.Count > 0)
GetFolder(oFld.item(), cTargetFolder)
}
oFld = null
}


function CopyFilename(oFolder, cTarget)
{
var oFiles = new Enumerator(oFolder.Files)
nCount = oFolder.Files.Count
var aFiles = new Array(nCount)
var aFileToCopy = new Array()
for (i = 0; i < nCount; i++)
{
aFiles = oFiles.item().Name
oFiles.moveNext()
}

aFiles = aFiles.sort()
cFile = aFiles[0]
j = 0
for (i=0; i < nCount; i++)
{
nLen = cFile.length
if (cFile.substr(0, nLen-7) != aFiles.substr(0, nLen-7))
{
cFile = aFiles
j++
}
aFileToCopy[j] = aFiles
}

cSource = cSrcDrive.substr(0,1) + cTarget.substr(1) + &quot;\\&quot;
cTarget = cTarget + &quot;\\&quot;

// Remove the remark &quot;//&quot; below to display the folder name
// WScript.Echo(cSource + &quot; -> copy to -> &quot; + cTarget)

for (i=0; i < aFileToCopy.length; i++)
oFSO.CopyFile(cSource+aFileToCopy, cTarget+aFileToCopy)

oFiles = null
aFiles = null
aFileToCopy = null
}
------------------[/ignore]

Regards

-- AirCon --
 
AirCon

Ok, it looks excellent, I will try it first thing Monday morning when I get to work.

Thanks so much for your time and work on this, I really appreciate it.

Cheers!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top