Hi - a client running a W2k domain w/XP Pro workstations (not that it's
specifically relevant) has currently got a slew of files in their main
shared folder tree, which they'd like to rename for organization/sorting
purposes. There are probably about 3000 files in total, in multiple
subfolders. They're mostly Office files (Word & Excel).

Currently, the files are named similarly to the following:

X-00-dd-mm-yy-keywords-author.doc

...where the "X" is some initial for the type of file (e.g. M=memo), "00" is
the last two digits of the project number, etc.


To make things easier to sort, they're looking at something like the
following, instead:

X-00-yyyy-mm-dd-keywords-author.doc


....I'd suggested that even if this is possible, it might be more useful to
use


yyyy-mm-dd-X-00-keywords-author.doc

for sorting purposes. However, as I'm a complete moron when it comes to this
sort of thing, I thought I'd post in here. I know how to do some extremely
simple things with batch files, and that's about it. I'd do a complete full
backup first, of course, and would run this overnight.

Anyone want to help me look brilliant for this client? I won't steal credit
for the idea; I told them I had no clue and was going to ask some smart
people.

Re: File renames, en masse by Paul

Paul
Mon Jan 29 10:18:31 CST 2007


"Lanwench [MVP - Exchange]"
<lanwench@heybuddy.donotsendme.unsolicitedmail.atyahoo.com> wrote in message
news:uJftlm6QHHA.1208@TK2MSFTNGP03.phx.gbl...
> Hi - a client running a W2k domain w/XP Pro workstations (not that it's
> specifically relevant) has currently got a slew of files in their main
> shared folder tree, which they'd like to rename for organization/sorting
> purposes. There are probably about 3000 files in total, in multiple
> subfolders. They're mostly Office files (Word & Excel).
>
> Currently, the files are named similarly to the following:
>
> X-00-dd-mm-yy-keywords-author.doc
>
> ...where the "X" is some initial for the type of file (e.g. M=memo), "00"
> is the last two digits of the project number, etc.
>
>
> To make things easier to sort, they're looking at something like the
> following, instead:
>
> X-00-yyyy-mm-dd-keywords-author.doc
>
>
> ....I'd suggested that even if this is possible, it might be more useful
> to use
>
>
> yyyy-mm-dd-X-00-keywords-author.doc
>
> for sorting purposes. However, as I'm a complete moron when it comes to
> this sort of thing, I thought I'd post in here. I know how to do some
> extremely simple things with batch files, and that's about it. I'd do a
> complete full backup first, of course, and would run this overnight.
>
> Anyone want to help me look brilliant for this client? I won't steal
> credit for the idea; I told them I had no clue and was going to ask some
> smart people.
Hi,
I assume you already know how to recurse through all the subfolders of a
starting folder. If not, google the VBscripting newsgroups. I also assume
you know how to access the subfolders and files collections of the file
system object's folder object. A file object's Name property can be used to
get the file's current name as well as to give it a new name.

It looks like your file names have three zones of interest:
1. A fixed-length zone (X-00-) that does not change
2. A fixed-length zone that increases in size by two bytes, with subzones
that are rearranged.
3. A variable length zone that does not change.

On thing you didn't specify is what to do when changing the old year from xx
to the new format of xxxx. Is the new year always 20xx or can it sometimes
be 19xx?

The four-line statement below will probably change the name to what you
want.
objFile.Name = Left(objFile.Name, 5) & _
"20" & Mid(objFile.Name, 12, 2) & _
Mid(objFile.Name, 5, 7) & _
Right(objFile.Name, Len(objFile.Name) - 16

-Paul Randall



Re: File renames, en masse by Lanwench

Lanwench
Mon Jan 29 22:03:15 CST 2007

In news:ugNlJE8QHHA.2252@TK2MSFTNGP02.phx.gbl,
Paul Randall <paulr901@cableone.net> typed:
> "Lanwench [MVP - Exchange]"
> <lanwench@heybuddy.donotsendme.unsolicitedmail.atyahoo.com> wrote in
> message news:uJftlm6QHHA.1208@TK2MSFTNGP03.phx.gbl...
>> Hi - a client running a W2k domain w/XP Pro workstations (not that
>> it's specifically relevant) has currently got a slew of files in
>> their main shared folder tree, which they'd like to rename for
>> organization/sorting purposes. There are probably about 3000 files
>> in total, in multiple subfolders. They're mostly Office files (Word
>> & Excel). Currently, the files are named similarly to the following:
>>
>> X-00-dd-mm-yy-keywords-author.doc
>>
>> ...where the "X" is some initial for the type of file (e.g. M=memo),
>> "00" is the last two digits of the project number, etc.
>>
>>
>> To make things easier to sort, they're looking at something like the
>> following, instead:
>>
>> X-00-yyyy-mm-dd-keywords-author.doc
>>
>>
>> ....I'd suggested that even if this is possible, it might be more
>> useful to use
>>
>>
>> yyyy-mm-dd-X-00-keywords-author.doc
>>
>> for sorting purposes. However, as I'm a complete moron when it comes
>> to this sort of thing, I thought I'd post in here. I know how to do
>> some extremely simple things with batch files, and that's about it.
>> I'd do a complete full backup first, of course, and would run this
>> overnight. Anyone want to help me look brilliant for this client? I won't
>> steal
>> credit for the idea; I told them I had no clue and was going to ask
>> some smart people.

> Hi,

Hey, Paul - thank you for the reply.

> I assume you already know how to recurse through all the subfolders
> of a starting folder.

<whistles casually, looks around room> Alas, no - I'm a complete newb with
this sort of thing. But I promise I'm not some kid trying to get someone to
do my homework for me and will happily answer any of your burning Exchange
questions :-)

> If not, google the VBscripting newsgroups.

Will do so as soon as I can figure out what to use for search parameters...

> I
> also assume you know how to access the subfolders and files
> collections of the file system object's folder object. A file
> object's Name property can be used to get the file's current name as
> well as to give it a new name.

<see above>


>
> It looks like your file names have three zones of interest:
> 1. A fixed-length zone (X-00-) that does not change
> 2. A fixed-length zone that increases in size by two bytes, with
> subzones that are rearranged.
> 3. A variable length zone that does not change.
>
> On thing you didn't specify is what to do when changing the old year
> from xx to the new format of xxxx. Is the new year always 20xx or
> can it sometimes be 19xx?
>
> The four-line statement below will probably change the name to what
> you want.
> objFile.Name = Left(objFile.Name, 5) & _
> "20" & Mid(objFile.Name, 12, 2) & _
> Mid(objFile.Name, 5, 7) & _
> Right(objFile.Name, Len(objFile.Name) - 16
>
> -Paul Randall



Re the yyyy - I think they've got some older files in this tree, but it's
also possible someone has already moved the pre-Y2k stuff out to another
volume where they used to do their archiving.

So, bearing in mind that I'm a complete tyro here, I'd take the above four
lines and save them in a whatever.vbs file ...yes? And I need to find out
how to run this against the tree so it will iteratively run through all the
subfolders. Do you know a decent site I can check out that spells out this
sort of thing (vbscripting, particularly) in introductory terms, for the lay
person?

I'm going to run the questions by my client (w/r/t the fixed-length
question) and will report back. I'll probably grab a copy of a few
folders/subfolders to play with, so I can test this without running the risk
of making a huge mess I don't know how to clean up. The witness protection
program won't take me on; I already asked.

Again, your help is very much appreciated.



RE: File renames, en masse by urkec

urkec
Tue Jan 30 10:16:00 CST 2007

Before trying to rename files, I think you should check for files that don't
match your naming scheme, and then decide what to do with those. Try running
this on your root folder to see what names don't match the pattern:

A-nn-nn-nn-nn-

If necessary, you could also check if the day, month and year portions are
valid.

Replace "C:\test" with your root folder. File names are stored in
"C:\badFileNames" and "C:\namesOK"

This will not try to delete or rename anything, but test everything first.


set fso = CreateObject _
("Scripting.FileSystemObject")
set startFolder = fso.GetFolder ("C:\test")
set badFileNames = fso.OpenTextFile _
("C:\badFileNames.txt", 2, true)
set namesOK = fso.OpenTextFile _
("C:\namesOK.txt", 2, true)

set r = new RegExp
r.Pattern = "^[A-Z](-\d{2}){4}-"
r.IgnoreCase = true

checkNames (startFolder)

Wscript.Echo "Done"

sub checkNames (folder)
for each file in folder.Files
if r.Test (file.Name) then
namesOK.WriteLine file.Path
else
badFileNames.WriteLine file.Path
end if
next
for each f in folder.Subfolders
checkNames (f)
next
end sub
--
urkec


"Lanwench [MVP - Exchange]" wrote:

> Hi - a client running a W2k domain w/XP Pro workstations (not that it's
> specifically relevant) has currently got a slew of files in their main
> shared folder tree, which they'd like to rename for organization/sorting
> purposes. There are probably about 3000 files in total, in multiple
> subfolders. They're mostly Office files (Word & Excel).
>
> Currently, the files are named similarly to the following:
>
> X-00-dd-mm-yy-keywords-author.doc
>
> ....where the "X" is some initial for the type of file (e.g. M=memo), "00" is
> the last two digits of the project number, etc.
>
>
> To make things easier to sort, they're looking at something like the
> following, instead:
>
> X-00-yyyy-mm-dd-keywords-author.doc
>
>
> .....I'd suggested that even if this is possible, it might be more useful to
> use
>
>
> yyyy-mm-dd-X-00-keywords-author.doc
>
> for sorting purposes. However, as I'm a complete moron when it comes to this
> sort of thing, I thought I'd post in here. I know how to do some extremely
> simple things with batch files, and that's about it. I'd do a complete full
> backup first, of course, and would run this overnight.
>
> Anyone want to help me look brilliant for this client? I won't steal credit
> for the idea; I told them I had no clue and was going to ask some smart
> people.
>
>
>

RE: File renames, en masse by urkec

urkec
Tue Jan 30 13:42:01 CST 2007

If you are not sure what naming scheme you're going to use, you could split
each file name into an array, so:

X-00-dd-mm-yy-keywords-author.doc, would be:

arr(0) = X
arr(1) = 00
arr(2) = dd
arr(3) = mm
arr(4) = yy
...

and then arrange the elements as you like.

I tried to rearrange

X-00-dd-mm-yy-keywords-author.doc

to be like this

X-00-yyyy-mm-dd-....

but you could use some other pattern, rearranging array elements . I also
didn't account for year < 2000, but that can be added. This takes file names
from C:\test and subfolders,doesn't rename files, but writes
old_name,new_name to C:\namesOK.txt . But be careful, I think you don't want
to end up with only half of the files renamed. First check consistency of
names.

set fso = CreateObject _
("Scripting.FileSystemObject")
set startFolder = fso.GetFolder ("C:\test")
set badFileNames = fso.OpenTextFile _
("C:\badFileNames.txt", 2, true)
set namesOK = fso.OpenTextFile _
("C:\namesOK.txt", 2, true)

set r = new RegExp
r.Pattern = "^[A-Z](-\d{2}){4}-"
r.IgnoreCase = true

changeNames (startFolder)

Wscript.Echo "Done"

sub changeNames (folder)
for each file in folder.Files
if r.Test (file.Name) then
arr = Split (file.Name, "-")
str = arr (0) & "-"
str = str & arr (1) & "-"
str = str & "20" & arr (4) & "-"
str = str & arr (3) & "-"
str = str & arr (2)
for i = 5 to UBound (arr)
str = str & "-" & arr (i)
next
namesOK.WriteLine file.Name & "," & str
else
badFileNames.WriteLine file.Path
end if
next
for each f in folder.Subfolders
changeNames (f)
next
end sub

--
urkec


"Lanwench [MVP - Exchange]" wrote:

> Hi - a client running a W2k domain w/XP Pro workstations (not that it's
> specifically relevant) has currently got a slew of files in their main
> shared folder tree, which they'd like to rename for organization/sorting
> purposes. There are probably about 3000 files in total, in multiple
> subfolders. They're mostly Office files (Word & Excel).
>
> Currently, the files are named similarly to the following:
>
> X-00-dd-mm-yy-keywords-author.doc
>
> ....where the "X" is some initial for the type of file (e.g. M=memo), "00" is
> the last two digits of the project number, etc.
>
>
> To make things easier to sort, they're looking at something like the
> following, instead:
>
> X-00-yyyy-mm-dd-keywords-author.doc
>
>
> .....I'd suggested that even if this is possible, it might be more useful to
> use
>
>
> yyyy-mm-dd-X-00-keywords-author.doc
>
> for sorting purposes. However, as I'm a complete moron when it comes to this
> sort of thing, I thought I'd post in here. I know how to do some extremely
> simple things with batch files, and that's about it. I'd do a complete full
> backup first, of course, and would run this overnight.
>
> Anyone want to help me look brilliant for this client? I won't steal credit
> for the idea; I told them I had no clue and was going to ask some smart
> people.
>
>
>

Re: File renames, en masse by Paul

Paul
Tue Jan 30 15:20:02 CST 2007


"Lanwench [MVP - Exchange]"
<lanwench@heybuddy.donotsendme.unsolicitedmail.atyahoo.com> wrote in message
news:%23ayiVOCRHHA.1212@TK2MSFTNGP03.phx.gbl...
> In news:ugNlJE8QHHA.2252@TK2MSFTNGP02.phx.gbl,
> Paul Randall <paulr901@cableone.net> typed:
>> "Lanwench [MVP - Exchange]"
>> <lanwench@heybuddy.donotsendme.unsolicitedmail.atyahoo.com> wrote in
>> message news:uJftlm6QHHA.1208@TK2MSFTNGP03.phx.gbl...
>
> So, bearing in mind that I'm a complete tyro here, I'd take the above four
> lines and save them in a whatever.vbs file ...yes? And I need to find out
> how to run this against the tree so it will iteratively run through all
> the subfolders. Do you know a decent site I can check out that spells out
> this sort of thing (vbscripting, particularly) in introductory terms, for
> the lay person?

Yes, first you get a file system object for the root folder of interest,
then you recurse through that folder and all its sub-folders, and loop
through the collection of files in these folders, renaming them using code
like those four lines.

In case you don't know what a file system object is:
VBScript is a simple programming language, that can manipulate numbers and
strings and provisionaly execute sections of code based on comparisons. By
itself, VBScript can ony interact with the world trough the keyboard and
computer screen. But it does have the capability to interact with 'COM'
objects. By default, Windows installs a bunch of such objects. They can
give access to the file system, the network, other computers on the network,
WWW, certain databases, most or all of the Microsoft Office applications
installed on the computer, etc. VBScript's CreateObject statement can
create, for example, file system objects, Internet Explorer objects, and
Microsoft Excel object, if they have been installed on your system. The
file system object has methods and properties that allow the script to do
almost anything with a file, including rename it.

> I'm going to run the questions by my client (w/r/t the fixed-length
> question) and will report back. I'll probably grab a copy of a few
> folders/subfolders to play with, so I can test this without running the
> risk of making a huge mess I don't know how to clean up. The witness
> protection program won't take me on; I already asked.
>
> Again, your help is very much appreciated.
>
Hi, Lanwench

There are a few essentials you need to learn scripting.
1. The scripting execution engine. If you have Internet Explorer, then you
have some version of Microsoft's VBScript and JScript engines. If you have
IE6, then you probably have the latest version. Microsoft says it will not
provide any more updates to VBScript. If you want to upgrade due to an old
version, you need to know that different versions of Windows may require
different versions of the scripting engine. Download here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=c717d943-7e4b-4622-86eb-95a22b832caa&DisplayLang=en

2. The documentation is definitely not perfect, but has both VBScript and
JScript examples for nearly everything a beginner needs to learn the
language. The examples are aimed towards script usage within HTML pages. I
think this project is more of a stand-alone application. Some translation
is needed to test the sample code in a stand-alone situation. Download docs
here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en

3. An editor that can save plain text files with the extension .VBS.
Notepad will do, but debugging is tedious with Notepad. When an error
occurs, the scripting engine tells you the line number and some other info
about the problem. About the second time you have to find line 111 in a
script you will understand the need for easily getting to a particular line.
If you have any Microsoft Office applications installed, then you likely
have an excellent editor called VBE installed and perhaps the Microsoft's
script debugger. I currently use a free multi-scripting-language editor,
PSPad, available from http://www.pspad.com/en/; it has few or no nags. A
VBScript-only editor I've started using which can do more for VBScripters,
but nags when you try to access a feature only available in the non-free
version, is VBSEdit, from www.vbsedit.com.

The best source of Windows scripting info is
http://www.microsoft.com/technet/scriptcenter/default.mspx
Novices should read the link for Scripting: Your First Steps

There are a few places with tutorials on VBScript but they are usually aimed
at VBScript in a web server and VBscript in a web page. After some
stumbling around, I think you will quickly learn to ignore the stumbling
blocks.

Googleing for the word free followed by the phrase in quotes "vbscript code"
will provide links to both code and tutorials.

http://www.w3schools.com/ has a lot of good tutorials/sample code, but all
is aimed at web pages. For playing with this, I sometimes use a free editor
from www.coffeecup.com. It's line numbering feature is somewhat broken, but
you can paste samples from HTML tutorials into the editing tab window and
then switch to the preview tab to see that HTML rendered, and interact
(click, fill in boxes, etc), just as if you had saved the code and opened it
in a browser. Its quick and easy to switch between modifying a script in
HTML and seeing the result of that modification.

There are lots of places with sample code which can be cut and pasted into
your projects. Often the sample code is poorly documented, but it is still
valuable in getting you going in the right direction. There are many
different ways to do the same thing. Ten commented statements
understandable only to a scripting Guru might produce the same result as 100
uncommented statements understandable by a novice. When things go wrong,
its is nice to be working with code you kind of understand.

As you browse Microsoft's newsgroups, pay particular attention to answers by
MVPs. These people have demonstrated the ability to provide good
information in the newsgroup. Scripts they post often contain useful
routines and techniques.

Many of the MVPs have web sites with excellent sample code like
Alex Angelopolous' http://dev.remotenetworktechnology.com/ and
Richard Mueller's http://www.rlmueller.net/products.htm
They often list their web site in their signature.

Go to Alex's site, navigate to the WSH and VBScript items and browse the few
lines of comments in most of the routines so you can get an idea of what's
there -- you will probably come back and get things of interest.



Re: File renames, en masse by Paul

Paul
Tue Jan 30 17:03:26 CST 2007


"Lanwench [MVP - Exchange]"
<lanwench@heybuddy.donotsendme.unsolicitedmail.atyahoo.com> wrote in message
news:%23ayiVOCRHHA.1212@TK2MSFTNGP03.phx.gbl...
> In news:ugNlJE8QHHA.2252@TK2MSFTNGP02.phx.gbl,
> Paul Randall <paulr901@cableone.net> typed:
>> "Lanwench [MVP - Exchange]"
>> <lanwench@heybuddy.donotsendme.unsolicitedmail.atyahoo.com> wrote in
>> message news:uJftlm6QHHA.1208@TK2MSFTNGP03.phx.gbl...
>> The four-line statement below will probably change the name to what
>> you want.
>> objFile.Name = Left(objFile.Name, 5) & _
>> "20" & Mid(objFile.Name, 12, 2) & _
>> Mid(objFile.Name, 5, 7) & _
>> Right(objFile.Name, Len(objFile.Name) - 16
>>
>> -Paul Randall
>
>
>
> Re the yyyy - I think they've got some older files in this tree, but it's
> also possible someone has already moved the pre-Y2k stuff out to another
> volume where they used to do their archiving.

If Windows Explorer shows the correct date, VBScript can use it in the file
name.

> So, bearing in mind that I'm a complete tyro here, I'd take the above four
> lines and save them in a whatever.vbs file ...yes? And I need to find out
> how to run this against the tree so it will iteratively run through all
> the subfolders. Do you know a decent site I can check out that spells out
> this sort of thing (vbscripting, particularly) in introductory terms, for
> the lay person?

Yes, starting at a base folder, the script can recurse through that folder
and all levels of subfolders to rename the files within those folders.

> I'm going to run the questions by my client (w/r/t the fixed-length
> question) and will report back. I'll probably grab a copy of a few
> folders/subfolders to play with, so I can test this without running the
> risk of making a huge mess I don't know how to clean up. The witness
> protection program won't take me on; I already asked.
>
> Again, your help is very much appreciated.
>
There are a few essentials you need to learn scripting.
1. The scripting execution engine. If you have Internet Explorer, then you
have some version of Microsoft's VBScript and JScript engines. If you have
IE6, then you probably have the latest version. Microsoft says it will not
provide any more updates to VBScript. If you want to upgrade due to an old
version, you need to know that different versions of Windows may require
different versions of the scripting engine. For W2K and WXP, download here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=c717d943-7e4b-4622-86eb-95a22b832caa&DisplayLang=en

2. The documentation is definitely not perfect, but has an excellent index
and examples of use of most key words in both VBScript and JScript. The
examples are aimed towards script usage within HTML pages. I think this
project is more of a stand-alone application. Some translation is needed to
test the sample code in a stand-alone situation. Download docs here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en

Read the VBScript User's Guide section - its listed in the index.

3. An editor that can save plain text files with the extension .VBS.
Notepad will do, but debugging is tedious with Notepad. When an error
occurs, the scripting engine tells you the line number and some other info
about the problem. About the second time you have to find line 111 in a
script you will understand the need for easily getting to a particular line.
If you have any Microsoft Office applications installed, then you likely
have an excellent editor called VBE installed and perhaps the Microsoft's
script debugger. I currently use a free multi-scripting-language editor,
PSPad, available from http://www.pspad.com/en/; it has few or no nags. A
VBScript-only editor I've started using which can do more for VBScripters,
but nags when you try to access a feature only available in the non-free
version, is VBSEdit, from www.vbsedit.com.

The best source of Windows scripting info is
http://www.microsoft.com/technet/scriptcenter/default.mspx
Novices should read the link for Scripting: Your First Steps

There are a few places with tutorials on VBScript but they are usually aimed
at VBScript in a web server and VBscript in a web page. After some
stumbling around, I think you will quickly learn to ignore the stumbling
blocks.

Googleing for the word free followed by the phrase in quotes "vbscript code"
will provide links to both code and tutorials.

http://www.w3schools.com/ has a lot of good tutorials/sample code, but all
is aimed at web pages. For playing with this, I sometimes use a free editor
from www.coffeecup.com. It's line numbering feature is somewhat broken, but
you can paste samples from HTML tutorials into the editing tab window and
then switch to the preview tab to see that HTML rendered, and interact
(click, fill in boxes, etc), just as if you had saved the code and opened it
in a browser. Its quick and easy to switch between modifying a script and
seeing the result of that modification.

There are lots of places with sample code which can be cut and pasted into
your projects. Often the sample code is poorly documented, but it is still
valuable in getting you going in the right direction. There are many
different ways to do the same thing. Ten commented statements
understandable only to a scripting Guru might produce the same result as 100
uncommented statements understandable by a novice. When things go wrong,
its is nice to be working with code you kind of understand.

As you browse Microsoft's newsgroups, pay particular attention to answers by
MVPs. These people have demonstrated the ability to provide good
information in the newsgroup. Scripts they post often contain useful
routines and techniques.

Many of the MVPs have web sites with excellent sample code like
Alex Angelopolous' http://dev.remotenetworktechnology.com/ and
Richard Mueller's http://www.rlmueller.net/products.htm
They often list their web site in their signature.

Go to Alex's site, navigate to the WSH and VBScript items and browse comment
lines in most of the routines so you can get an idea of whats there -- you
will probably come back and get things of interest.

-Paul Randall



Re: File renames, en masse by Paul

Paul
Tue Jan 30 17:14:25 CST 2007


"Ayush" <"ayushmaan.j[aatt]gmail.com"> wrote in message
news:%23lK5HCDRHHA.3500@TK2MSFTNGP05.phx.gbl...
> Replied to [Lanwench [MVP - Exchange]]s message :
>> Hi - a client running a W2k domain w/XP Pro workstations (not that it's
>> specifically relevant) has currently got a slew of files in their main
>> shared folder tree, which they'd like to rename for organization/sorting
>> purposes. There are probably about 3000 files in total, in multiple
>> subfolders. They're mostly Office files (Word & Excel).
>>
>> Currently, the files are named similarly to the following:
>>
>> X-00-dd-mm-yy-keywords-author.doc
>>
>> To make things easier to sort, they're looking at something like the
>> following, instead:
>>
>> X-00-yyyy-mm-dd-keywords-author.doc
>
>
>
>
>
> --
> ? Ayush
> -------------
> Search - www.Google.com | Wikipedia - http://en.wikipedia.org
> Snip your long urls - http://snipurl.com/
> -------------
>


--------------------------------------------------------------------------------


> 'Change file names from :
> ' X-00-dd-mm-yy-keywords-author.doc to:
> ' X-00-yy-mm-dd-keywords-author.doc
> 'Ayush
>
> Set fldr = CreateObject("Shell.Application").BrowseForFolder(0,"Select a
> folder ..",0,17)
> If fldr Is Nothing Then
> WScript.Quit
> Else
> Set fo = CreateObject("Scripting.FileSystemObject")
> Set fldr= fo.GetFolder (fldr.Self.Path)
> End If
> If MsgBox("Run the script on folder """ & fldr.Path & """ ?" & vbCr& vbCr
> & "Important Note : Backup your files before running the
> script.",vbYesNo,"Are you sure ?")=vbNo Then WScript.Quit
>
> Set Rxp = New RegExp : Rxp.IgnoreCase = true
> Rxp.Pattern =
> "^(\w)-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(.*)-(.*)\.(doc|xls)$"
>
> SubR fldr
> Sub SubR (fObj)
> For Each Subf In fObj.SubFolders
> For Each Fl In Subf.Files
> If Rxp.Test(Fl.Name) Then
> '********
> Fl.Name = Rxp.Replace(Fl.Name,"$1-$2-$5-$4-$3-$6-$7.$8")
> End If
> Next
> SubR Subf
> Next
> End Sub
>
> '*******
> 'this will change to: X-00-yy-mm-dd-keywords-author.doc/xls
> 'if you want: yy-mm-dd-X-00-keywords-author.doc/xls then change
> 'everything in following string($1-$2-$5-$4-$3-$6-$7.$8) to :
> '$5-$4-$3-$1-$2-$6-$7.$8

Hi, Ayush
I was hoping you would post some sample code. But since Lanwench is a
novice to VBScript, I think using RegExp may be difficult to understand. On
the other hand, since RegExp is so powerful and compact, Lanwench is a MVP,
that may be a plus.

-Paul Randall



Re: File renames, en masse by Lanwench

Lanwench
Wed Jan 31 20:17:14 CST 2007

In news:eVtoaLMRHHA.488@TK2MSFTNGP06.phx.gbl,
Paul Randall <paulr901@cableone.net> typed:
> "Lanwench [MVP - Exchange]"
> <lanwench@heybuddy.donotsendme.unsolicitedmail.atyahoo.com> wrote in
> message news:%23ayiVOCRHHA.1212@TK2MSFTNGP03.phx.gbl...
>> In news:ugNlJE8QHHA.2252@TK2MSFTNGP02.phx.gbl,
>> Paul Randall <paulr901@cableone.net> typed:
>>> "Lanwench [MVP - Exchange]"
>>> <lanwench@heybuddy.donotsendme.unsolicitedmail.atyahoo.com> wrote in
>>> message news:uJftlm6QHHA.1208@TK2MSFTNGP03.phx.gbl...
>>> The four-line statement below will probably change the name to what
>>> you want.
>>> objFile.Name = Left(objFile.Name, 5) & _
>>> "20" & Mid(objFile.Name, 12, 2) & _
>>> Mid(objFile.Name, 5, 7) & _
>>> Right(objFile.Name, Len(objFile.Name) - 16
>>>
>>> -Paul Randall
>>
>>
>>
>> Re the yyyy - I think they've got some older files in this tree, but
>> it's also possible someone has already moved the pre-Y2k stuff out
>> to another volume where they used to do their archiving.
>
> If Windows Explorer shows the correct date, VBScript can use it in
> the file name.
>
>> So, bearing in mind that I'm a complete tyro here, I'd take the
>> above four lines and save them in a whatever.vbs file ...yes? And I
>> need to find out how to run this against the tree so it will
>> iteratively run through all the subfolders. Do you know a decent
>> site I can check out that spells out this sort of thing
>> (vbscripting, particularly) in introductory terms, for the lay
>> person?
>
> Yes, starting at a base folder, the script can recurse through that
> folder and all levels of subfolders to rename the files within those
> folders.
>> I'm going to run the questions by my client (w/r/t the fixed-length
>> question) and will report back. I'll probably grab a copy of a few
>> folders/subfolders to play with, so I can test this without running
>> the risk of making a huge mess I don't know how to clean up. The
>> witness protection program won't take me on; I already asked.
>>
>> Again, your help is very much appreciated.
>>
> There are a few essentials you need to learn scripting.
> 1. The scripting execution engine. If you have Internet Explorer,
> then you have some version of Microsoft's VBScript and JScript
> engines. If you have IE6, then you probably have the latest version.
> Microsoft says it will not provide any more updates to VBScript. If
> you want to upgrade due to an old version, you need to know that
> different versions of Windows may require different versions of the
> scripting engine. For W2K and WXP, download here:
> http://www.microsoft.com/downloads/details.aspx?FamilyID=c717d943-7e4b-4622-86eb-95a22b832caa&DisplayLang=en
>
> 2. The documentation is definitely not perfect, but has an excellent
> index and examples of use of most key words in both VBScript and
> JScript. The examples are aimed towards script usage within HTML
> pages. I think this project is more of a stand-alone application. Some
> translation is needed to test the sample code in a stand-alone
> situation. Download docs here:
> http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en
>
> Read the VBScript User's Guide section - its listed in the index.
>
> 3. An editor that can save plain text files with the extension .VBS.
> Notepad will do, but debugging is tedious with Notepad. When an error
> occurs, the scripting engine tells you the line number and some other
> info about the problem. About the second time you have to find line
> 111 in a script you will understand the need for easily getting to a
> particular line. If you have any Microsoft Office applications
> installed, then you likely have an excellent editor called VBE
> installed and perhaps the Microsoft's script debugger. I currently
> use a free multi-scripting-language editor, PSPad, available from
> http://www.pspad.com/en/; it has few or no nags. A VBScript-only
> editor I've started using which can do more for VBScripters, but nags
> when you try to access a feature only available in the non-free
> version, is VBSEdit, from www.vbsedit.com.
> The best source of Windows scripting info is
> http://www.microsoft.com/technet/scriptcenter/default.mspx
> Novices should read the link for Scripting: Your First Steps
>
> There are a few places with tutorials on VBScript but they are
> usually aimed at VBScript in a web server and VBscript in a web page.
> After some stumbling around, I think you will quickly learn to ignore
> the stumbling blocks.
>
> Googleing for the word free followed by the phrase in quotes
> "vbscript code" will provide links to both code and tutorials.
>
> http://www.w3schools.com/ has a lot of good tutorials/sample code,
> but all is aimed at web pages. For playing with this, I sometimes
> use a free editor from www.coffeecup.com. It's line numbering
> feature is somewhat broken, but you can paste samples from HTML
> tutorials into the editing tab window and then switch to the preview
> tab to see that HTML rendered, and interact (click, fill in boxes,
> etc), just as if you had saved the code and opened it in a browser. Its
> quick and easy to switch between modifying a script and seeing
> the result of that modification.
> There are lots of places with sample code which can be cut and pasted
> into your projects. Often the sample code is poorly documented, but
> it is still valuable in getting you going in the right direction. There
> are many different ways to do the same thing. Ten commented
> statements understandable only to a scripting Guru might produce the
> same result as 100 uncommented statements understandable by a novice.
> When things go wrong, its is nice to be working with code you kind
> of understand.
> As you browse Microsoft's newsgroups, pay particular attention to
> answers by MVPs. These people have demonstrated the ability to
> provide good information in the newsgroup. Scripts they post often
> contain useful routines and techniques.
>
> Many of the MVPs have web sites with excellent sample code like
> Alex Angelopolous' http://dev.remotenetworktechnology.com/ and
> Richard Mueller's http://www.rlmueller.net/products.htm
> They often list their web site in their signature.
>
> Go to Alex's site, navigate to the WSH and VBScript items and browse
> comment lines in most of the routines so you can get an idea of whats
> there -- you will probably come back and get things of interest.
>
> -Paul Randall


Thank you again, Paul - I'll take all your advice under consideration. The
client is now rethinking the decision to script this stuff anyway, as it
turns out the file naming convention they've been using isn't actually very
consistent - and this makes it somewhat a moot point for the moment. I do
need to get up to snuff on this sort of thing, though, I think - and I
appreciate your help. I do pay attention to MVP answers....it'd be silly for
me not to. :-)



Re: File renames, en masse by Lanwench

Lanwench
Wed Jan 31 20:18:44 CST 2007

In news:%23lK5HCDRHHA.3500@TK2MSFTNGP05.phx.gbl,
Ayush" <"ayushmaan.j[aatt]gmail.com <"ayushmaan.j[aatt]gmail.com"> typed:
>> Replied to [Lanwench [MVP - Exchange]]s message :
>>> Hi - a client running a W2k domain w/XP Pro workstations (not that
>>> it's specifically relevant) has currently got a slew of files in
>>> their main shared folder tree, which they'd like to rename for
>>> organization/sorting purposes. There are probably about 3000 files
>>> in total, in multiple subfolders. They're mostly Office files
>>> (Word & Excel).
>>>
>>> Currently, the files are named similarly to the following:
>>>
>>> X-00-dd-mm-yy-keywords-author.doc
>>>
>>> To make things easier to sort, they're looking at something like the
>>> following, instead:
>>>
>>> X-00-yyyy-mm-dd-keywords-author.doc
>>
>>
>>
>>
>>
>> --
>> ? Ayush
>> -------------
>> Search - www.Google.com | Wikipedia - http://en.wikipedia.org
>> Snip your long urls - http://snipurl.com/
>> -------------
<snip>

Thank you much, Ayush - this is becoming very helpful info. Most kind of
you.



Re: File renames, en masse by Lanwench

Lanwench
Wed Jan 31 20:18:18 CST 2007

In news:DD795EFE-21A9-4F3F-BE19-BC6192DEB2DE@microsoft.com,
urkec <urkec@discussions.microsoft.com> typed:
> If you are not sure what naming scheme you're going to use, you could
> split each file name into an array, so:
>
> X-00-dd-mm-yy-keywords-author.doc, would be:
>
> arr(0) = X
> arr(1) = 00
> arr(2) = dd
> arr(3) = mm
> arr(4) = yy
> ...
>
<snip>

Thank you, urkec - I appreciate the reply. For the time being the entire
project's in a hold state but I'm learning a lot in here :)



Re: File renames, en masse by Ayush

Ayush
Thu Feb 01 10:48:35 CST 2007

Replied to [Lanwench [MVP - Exchange]]s message :
> Thank you much, Ayush - this is becoming very helpful info. Most kind of
> you.


You are welcome. Glad to help.

--
â?? Ayush
-------------
Search - www.Google.com | Wikipedia - http://en.wikipedia.org
Snip your long urls - http://snipurl.com/
-------------