Automated file renaming program?

P

Phred

G'day mates,

I have a file renaming problem for which I hope someone may be able to
point me to a practical solution, please. Either a cheap (or free :)
existing application, or guidance on how to create a suitable batch
routine (Windows ME and/or Windows 2000/XP) would be acceptable
solutions, if practical.

The files are data files captured every 3 hours (but usually only
about six files/day on average after allowing for corrupted and/or
"nonexistent" files) and they are transferred to a PC approximately
every 3 days (or less) to ensure some are not lost. (While the source
system can actually store up to 26 files before the FIFO rule is
applied, that's still only about 3 days of a really good run.)

The naming convention on the source system is numerically newest to
oldest with two digits (i.e. NAME01.EXT to NAME26.EXT where 01 is the
current file and 26 the oldest). The oldest file (26) is dropped at
the next data input when the file names in the remainder of the set
are incremented and a new 01 is added.

When transferred to PC, the files are stored in a structure that looks
like:

C:\level1\level2\level3\DATASET\yymmddhh\NAME##.EXT

where yymmddhh is simply code for year/month/day/hour when downloaded
and ## is 01 to 26 (max) as explained above. [In fact, there are
several DATASETs involved, with currently between 100 and 200 of those
yymmddhh subdirs in each. While that shouldn't affect the logic of
any proposed solution, it does explain why I'm keen to have the
process automated as far as possible!]

With me so far?

Okay, what I want to end up with is a numerical sequence of files
within ~\DATASET\ which runs from oldest to newest (i.e. the oldest
file becomes 0001 and the newest is NNNN, where 0001 <NNNN <=9999 ) so
the naming scheme is essentially open-ended. [Note that "oldest" and
"newest" are defined by the file names and *not* necessarily by file
creation date as stored on the HDD.]

In fact, I would like to be able to define subsets of these sequences,
based on a span of dates in that yymmddhh format that conforms to the
subdirectory naming scheme. Whether each of the subsets starts again
from 1=oldest, or simply continues the sequence from the previous
subset, is a moot point as there are potential advantages in both
approaches. But if the latter is adopted, it probably means using a
base starting at 00001 if it's to be used in the reasonably long term
-- or even 000001, remembering the millennium. ;-)

So let's assume the latter (starting from 1 then just becomes a
particular case). To simplify things a bit, it would be acceptable to
assume the renaming logic starts from a particular DATASET as the
"current directory" (though changing to that would probably be only a
trivial complication anyway).

I would then like to specify:
1. A range of subdirectories to operate on at the next level in the
form yymmddhh (e.g. 04022106 to 04040712)

2. A "root" alphanumeric file name for the series (probably just 2
characters in order to keep to a standard 8.3 file name) and

3. A sequence starting number in the form NNNNNN, which could be
explicitly stated or, if not, then defaults to a previously stored
number based on the previous run IN THAT DATASET so the sequence
continues incrementing logically from that previous point.

It would be necessary for the programmed solution to sort the yymmddhh
directories to be processed in ascending order, and then sort and
process the files within each in descending order of the original
names but ascending order of the newly assigned names; with a "carry"
of the sequence into the next yymmddhh directory in the set.

Note that the renamed files are to be transferred to a common
location (preferably specified as part of the process; but a built-in
"temporary" location would be acceptable if necessary). They are NOT
to be renamed and left in situ in that myriad of yymmddhh subdirs.

It would also be preferable, though not essential, to COPY/RENAME the
files to the new location as part of the renaming, rather than doing a
MOVE/RENAME. [Not essential because the alternative option would be
to create a duplicate set to work on prior to doing the job, rather
than making the duplicate set as part of the renaming procedure.]

Thanks very much for your interest in at least reading this far!


Cheers, Phred.
 
N

null

G'day mates,

I have a file renaming problem for which I hope someone may be able to
point me to a practical solution, please. Either a cheap (or free :)
existing application, or guidance on how to create a suitable batch
routine (Windows ME and/or Windows 2000/XP) would be acceptable
solutions, if practical.

<snip>

If you haven't, I suggest posting to alt.msdos.batch for the Win ME
solution and alt.msdos.batch.nt for the NT based OS solution
(solutions may be somewhat different). The regulars on these groups
are truly amazing and helpful.


Art
http://www.epix.net/~artnpeg
 
M

Matthias Tacke

Phred said:
G'day mates,

I have a file renaming problem for which I hope someone may be able to
point me to a practical solution, please. Either a cheap (or free :)
existing application, or guidance on how to create a suitable batch
routine (Windows ME and/or Windows 2000/XP) would be acceptable
solutions, if practical.
Oh gee, a 5k question that is rare :)

I strongly suggest using batch from w2k on. All the needed features are
there. An off the shelf program won't be able to do that.

Assuming the files are unique (don't overlap from yymmddhh folder to the
next) I'd rename the files to yymmddhh(27-actualnumber).ext and move
them to the basefolder of the dataset.

I didn't snip the following, see remarks at the end.
The files are data files captured every 3 hours (but usually only
about six files/day on average after allowing for corrupted and/or
"nonexistent" files) and they are transferred to a PC approximately
every 3 days (or less) to ensure some are not lost. (While the source
system can actually store up to 26 files before the FIFO rule is
applied, that's still only about 3 days of a really good run.)

The naming convention on the source system is numerically newest to
oldest with two digits (i.e. NAME01.EXT to NAME26.EXT where 01 is the
current file and 26 the oldest). The oldest file (26) is dropped at
the next data input when the file names in the remainder of the set
are incremented and a new 01 is added.

When transferred to PC, the files are stored in a structure that looks
like:

C:\level1\level2\level3\DATASET\yymmddhh\NAME##.EXT

where yymmddhh is simply code for year/month/day/hour when downloaded
and ## is 01 to 26 (max) as explained above. [In fact, there are
several DATASETs involved, with currently between 100 and 200 of those
yymmddhh subdirs in each. While that shouldn't affect the logic of
any proposed solution, it does explain why I'm keen to have the
process automated as far as possible!]

With me so far?

Okay, what I want to end up with is a numerical sequence of files
within ~\DATASET\ which runs from oldest to newest (i.e. the oldest
file becomes 0001 and the newest is NNNN, where 0001 <NNNN <=9999 ) so
the naming scheme is essentially open-ended. [Note that "oldest" and
"newest" are defined by the file names and *not* necessarily by file
creation date as stored on the HDD.]

In fact, I would like to be able to define subsets of these sequences,
based on a span of dates in that yymmddhh format that conforms to the
subdirectory naming scheme. Whether each of the subsets starts again
from 1=oldest, or simply continues the sequence from the previous
subset, is a moot point as there are potential advantages in both
approaches. But if the latter is adopted, it probably means using a
base starting at 00001 if it's to be used in the reasonably long term

Foxidrive and me codeveloped a comfortable renumbering batch for your
next step. It allows a prefix, the number of placs, the starting number
and even an interval to be given. It was published in
That is also the appropriate group for my
suggestion. So:

X'Post + F'up2 ambn
 
R

Richard Bonner

Phred said:
G'day mates,

*** Howdy from Canada.

I have a file renaming problem for which I hope someone may be able to
point me to a practical solution, please. Either a cheap (or free :)
existing application, or guidance on how to create a suitable batch
routine (Windows ME and/or Windows 2000/XP) would be acceptable
solutions, if practical. (Snip)

Cheers, Phred.

*** Yow! You need a lot done. I don't run Windows and this will not solve
your problem, but it may get you started. Have a look at SEQ.bat and
PROJ-SEQ.bat at:

www.chebucto.ns.ca/ak621/DOS/Bat-Adv3.html

This will sequence files in numerical order, but what will have to be
passed to PROJ-SEQ.bat is your list of files in reverse order. That can be
done, but I don't presently have the time to sort out the details to do
exactly what you want right now... and of course, since you are on the
other side of The International Date Line, you'll need this done
yesterday. (-:

For part of the rest of what you need, naming files or folders by date
is handled by "DATEFILE.bat" and DATE-DIR.bat" at:

www.chebucto.ns.ca/ak621/DOS/Bat-Adv2.html

Try working with those batch files to see how far you get and then
post back here.

Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
 
F

foxidrive

G'day mates,

G'day cobber.
I have a file renaming problem for which I hope someone may be able to
point me to a practical solution, please. Either a cheap (or free :)
existing application, or guidance on how to create a suitable batch
routine (Windows ME and/or Windows 2000/XP) would be acceptable
solutions, if practical.

This is designed for W2k/XP and the limitations are that it is primarily
meant for years after 1999, though that may not matter come to think about
it. The other limitation is that it's had bugger all testing.

The Syntax is filename.bat yymmddhh yymmddhh num prefix

the first two are directory dates to start and finish at
the num is a numeral to start numbering at, without leading zeros (6 digits
will be used)
and the prefix is a 2 character word.


As it stands it won't do a bloody thing, except print to the screen the
rename commands it *would* do if the echo is removed from the last line.
Lemme know how it works, good or bad.



@echo off
if [%4]==[] (
echo Start_dir_num End_dir_num Start_num prefix & goto :EOF
)
set startdir=20%1
set enddir=20%2
set count=%3
set prefix=%4
set /a count-=1
setlocal EnableExtensions EnableDelayedExpansion
for /f "delims=" %%a in ('dir /a:d /s /b /on') do (
for /f "delims=" %%b in ('dir "%%a" /a:-d /b /o-n') do (
call :ren "%%a\%%b" "%%a"
)
)
goto :EOF

:ren
set dircount=%~n2
if 20%dircount% LSS %startdir% goto :EOF
if 20%dircount% GTR %enddir% goto :EOF
set /a count+=1
set num=%count% 000000
set num=%num:~0,7%
for /f "tokens=1,2 delims= " %%c in ("%num%") do set num=%%d%%c
echo ren %1 "%prefix%%num%.*"
 
F

foxidrive

This is an updated message as I don't know how useful supercedes are if
some servers may reject them.


I had missed the requirement for a duplicate set of files, so this creates
the duplicate set in "\tempdir".

As before it only echos the commands to the screen.

To Matthias - I should have thought of our renaming effort earlier. :)


G'day mates,

G'day cobber.
I have a file renaming problem for which I hope someone may be able to
point me to a practical solution, please. Either a cheap (or free :)
existing application, or guidance on how to create a suitable batch
routine (Windows ME and/or Windows 2000/XP) would be acceptable
solutions, if practical.

This is designed for W2k/XP and the limitations are that it is primarily
meant for years after 1999, though that may not matter come to think about
it. The other limitation is that it's had bugger all testing.

The Syntax is filename.bat yymmddhh yymmddhh num prefix

the first two are directory dates to start and finish at
the num is a numeral to start numbering at, without leading zeros (6 digits
will be used)
and the prefix is a 2 character word.


As it stands it won't do a bloody thing, except print to the screen the
rename commands it *would* do if the echo is removed from the last line.
Lemme know how it works, good or bad.



@echo off
if [%4]==[] (
echo Start_dir_num End_dir_num Start_num prefix & goto :EOF
)
setlocal EnableExtensions EnableDelayedExpansion
set startdir=20%1
set enddir=20%2
set count=%3
set prefix=%4
set /a count-=1
md "\tempdir"
for /f "delims=" %%a in ('dir /a:d /s /b /on') do (
for /f "delims=" %%b in ('dir "%%a" /a:-d /b /o-n') do (
call :ren "%%a\%%b" "%%a"
)
)
goto :EOF

:ren
set dircount=%~n2
if 20%dircount% LSS %startdir% goto :EOF
if 20%dircount% GTR %enddir% goto :EOF
set /a count+=1
set num=%count% 000000
set num=%num:~0,7%
for /f "tokens=1,2 delims= " %%c in ("%num%") do set num=%%d%%c
echo copy /b %1 "\tempdir\%prefix%%num%.*"
 
R

Rod Speed

I'd personally cut to the chase and write a small app in a
free language that does all the file copying and renaming.

Even VBA which is included with Office
will do it fine, using the FileSystemObject.

Phred said:
G'day mates,

I have a file renaming problem for which I hope someone may be able to
point me to a practical solution, please. Either a cheap (or free :)
existing application, or guidance on how to create a suitable batch
routine (Windows ME and/or Windows 2000/XP) would be acceptable
solutions, if practical.

The files are data files captured every 3 hours (but usually only
about six files/day on average after allowing for corrupted and/or
"nonexistent" files) and they are transferred to a PC approximately
every 3 days (or less) to ensure some are not lost. (While the source
system can actually store up to 26 files before the FIFO rule is
applied, that's still only about 3 days of a really good run.)

The naming convention on the source system is numerically newest to
oldest with two digits (i.e. NAME01.EXT to NAME26.EXT where 01 is the
current file and 26 the oldest). The oldest file (26) is dropped at
the next data input when the file names in the remainder of the set
are incremented and a new 01 is added.

When transferred to PC, the files are stored in a structure that looks
like:

C:\level1\level2\level3\DATASET\yymmddhh\NAME##.EXT

where yymmddhh is simply code for year/month/day/hour when downloaded
and ## is 01 to 26 (max) as explained above. [In fact, there are
several DATASETs involved, with currently between 100 and 200 of those
yymmddhh subdirs in each. While that shouldn't affect the logic of
any proposed solution, it does explain why I'm keen to have the
process automated as far as possible!]

With me so far?

Okay, what I want to end up with is a numerical sequence of files
within ~\DATASET\ which runs from oldest to newest (i.e. the oldest
file becomes 0001 and the newest is NNNN, where 0001 <NNNN <=9999 ) so
the naming scheme is essentially open-ended. [Note that "oldest" and
"newest" are defined by the file names and *not* necessarily by file
creation date as stored on the HDD.]

In fact, I would like to be able to define subsets of these sequences,
based on a span of dates in that yymmddhh format that conforms to the
subdirectory naming scheme. Whether each of the subsets starts again
from 1=oldest, or simply continues the sequence from the previous
subset, is a moot point as there are potential advantages in both
approaches. But if the latter is adopted, it probably means using a
base starting at 00001 if it's to be used in the reasonably long term
-- or even 000001, remembering the millennium. ;-)

So let's assume the latter (starting from 1 then just becomes a
particular case). To simplify things a bit, it would be acceptable to
assume the renaming logic starts from a particular DATASET as the
"current directory" (though changing to that would probably be only a
trivial complication anyway).

I would then like to specify:
1. A range of subdirectories to operate on at the next level in the
form yymmddhh (e.g. 04022106 to 04040712)

2. A "root" alphanumeric file name for the series (probably just 2
characters in order to keep to a standard 8.3 file name) and

3. A sequence starting number in the form NNNNNN, which could be
explicitly stated or, if not, then defaults to a previously stored
number based on the previous run IN THAT DATASET so the sequence
continues incrementing logically from that previous point.

It would be necessary for the programmed solution to sort the yymmddhh
directories to be processed in ascending order, and then sort and
process the files within each in descending order of the original
names but ascending order of the newly assigned names; with a "carry"
of the sequence into the next yymmddhh directory in the set.

Note that the renamed files are to be transferred to a common
location (preferably specified as part of the process; but a built-in
"temporary" location would be acceptable if necessary). They are NOT
to be renamed and left in situ in that myriad of yymmddhh subdirs.

It would also be preferable, though not essential, to COPY/RENAME the
files to the new location as part of the renaming, rather than doing a
MOVE/RENAME. [Not essential because the alternative option would be
to create a duplicate set to work on prior to doing the job, rather
than making the duplicate set as part of the renaming procedure.]

Thanks very much for your interest in at least reading this far!


Cheers, Phred.
 
C

Charlie

didn't bother reading the whole post (yes, I'm lazy :))
but try file fiddler.

Charlie
 
P

Phred

<snip>

If you haven't, I suggest posting to alt.msdos.batch for the Win ME
solution and alt.msdos.batch.nt for the NT based OS solution
(solutions may be somewhat different). The regulars on these groups
are truly amazing and helpful.

Thanks for your suggestion, Art.

In fact I did include alt.msdos.batch initially, but so far yours is
the only response I've seen. (Mind you, it wasn't a simple problem,
so perhaps the gurus are still working on it. :)


Cheers, Phred.
 
P

Phred

G'day Foxidrive, Matthias, Rod, Richard and others,

Thanks for your responses. I'll have a crack at Foxidrive's and/or
Rod's solutions to start with and let you know how I go. But don't
hold your breath -- it may not be until next week that I get a serious
opportunity to try these things.

Richard, I tried to have a quick squiz at your links, but in both
cases all I got was:
<quoting>
Error:
We're sorry, but the file you requested was not found on this server.
Please check the address you requested:
[blah, blah, ...]
</quoting>

Charlie, I don't think File Fiddler is up to this task, but I'll keep
it in mind for the future needs. Thank you.

[email protected] (Richard said:
Phred said:
I have a file renaming problem for which I hope someone may be able to
point me to a practical solution, please. Either a cheap (or free :)
existing application, or guidance on how to create a suitable batch
routine (Windows ME and/or Windows 2000/XP) would be acceptable
solutions, if practical.
(Snip)

[...] Have a look at SEQ.bat and PROJ-SEQ.bat at:

www.chebucto.ns.ca/ak621/DOS/Bat-Adv3.html

This will sequence files in numerical order, but what will have to be
passed to PROJ-SEQ.bat is your list of files in reverse order. That can be
done, but I don't presently have the time to sort out the details to do
exactly what you want right now... and of course, since you are on the
other side of The International Date Line, you'll need this done
yesterday. (-:

For part of the rest of what you need, naming files or folders by date
is handled by "DATEFILE.bat" and DATE-DIR.bat" at:

www.chebucto.ns.ca/ak621/DOS/Bat-Adv2.html

Try working with those batch files to see how far you get and then
post back here.


Cheers, Phred.
 
R

Richard Bonner

Phred said:
Richard, I tried to have a quick squiz at your links, but in both
cases all I got was:
<quoting>
Error:
We're sorry, but the file you requested was not found on this server.
Please check the address you requested:
[blah, blah, ...]
</quoting>

*** Oh, sorry. I have having trouble getting an ASPECT script file to
print a tilde to the screen. Here are the corrected URLS:

www.chebucto.ns.ca/~ak621/DOS/Bat-Adv2.html
www.chebucto.ns.ca/~ak621/DOS/Bat-Adv3.html


Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
 
P

Phred

Phred said:
Richard, I tried to have a quick squiz at your links, but in both
cases all I got was:
<quoting>
Error:
We're sorry, but the file you requested was not found on this server.
Please check the address you requested:
[blah, blah, ...]
</quoting>

*** Oh, sorry. I have having trouble getting an ASPECT script file to
print a tilde to the screen. Here are the corrected URLS:

www.chebucto.ns.ca/~ak621/DOS/Bat-Adv2.html
www.chebucto.ns.ca/~ak621/DOS/Bat-Adv3.html

Ah! They work nicely now, thank you.
(P.S. You seem to have quite a bit of interesting stuff on that site
of yours. :)


Cheers, Phred.
 
R

Richard Bonner

Ah! They work nicely now, thank you.

*** You're welcome. I must peruse the manual and see how to have ASPECT
place that tilde. (-:

(P.S. You seem to have quite a bit of interesting stuff on that site
of yours. :)

Cheers, Phred.

*** Thank you. When I decided to make a DOS website, I wanted something
different looking, and to also have something with different content from
what most other DOS sites had.

Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top