Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the board
Thread view  Mix view  Order
Torsten

09.06.2017, 11:23
 

Batch program for natural to 7-digit file name conversion? (Miscellaneous)

Dear all,

I need to transfer data between different programs. However, the names
of the files with the respective data follow different conventions:
the input uses natural numbers for files names (i.e. 1, 2 ... 999999),
whereas the target program requires seven-digit file names, with leading
zeroes (0000001, 0000002 ... 0999999, 1000000) to order them properly.

I wonder whether such conversion could be done with a batch program's
"FOR %variable IN (set) DO"-loops, or if a more complex command set is
required. Maybe with a 4DOS's .BTM batch file, or using a script
language (Perl, Java, Rexx)?

Thanks for input, Torsten

tom

Homepage

Germany (West),
09.06.2017, 13:02

@ Torsten

Batch program for natural to 7-digit file name conversion?

> Dear all,
>
> I need to transfer data between different programs. However, the names
> of the files with the respective data follow different conventions:
> the input uses natural numbers for files names (i.e. 1, 2 ... 999999),
> whereas the target program requires seven-digit file names, with leading
> zeroes (0000001, 0000002 ... 0999999, 1000000) to order them properly.
>
> I wonder whether such conversion could be done with a batch program's
> "FOR %variable IN (set) DO"-loops, or if a more complex command set is
> required. Maybe with a 4DOS's .BTM batch file, or using a script
> language (Perl, Java, Rexx)?
>
> Thanks for input, Torsten

FOR %%i IN (?) DO call move.bat %%i 000000%%i
FOR %%i IN (??) DO call move.bat %%i 00000%%i
...

move.bat:
move /Y srcdir\%1 destdir
ren destdir\%1 %2

**** OR even better ******
FOR %%i IN (?) DO ren %%i 0%%i
FOR %%i IN (??) DO ren %%i 0%%i
FOR %%i IN (???) DO ren %%i 0%%i
FOR %%i IN (????) DO ren %%i 0%%i
FOR %%i IN (?????) DO ren %%i 0%%i
FOR %%i IN (??????) DO ren %%i 0%%i
FOR %%i IN (???????) DO ren %%i 0%%i

*** both methods assume there are only files to be converted in the directory

Torsten

28.06.2017, 13:29

@ tom

Batch program for natural to 7-digit file name conversion?

> @ECHO OFF
> REM Batch file 00RENAME June 9, 2017 by Tom E., renames files using natural
> REM numbers as names (1, 2 ... 999999) to file names with leading zeroes
> REM (0000001, 0000002 ... 0999999). Helps to overcome different ordering
> REM conventions when transferring data from one program to another. Caution:
> REM in the current directory, any file without an extension will be renamed.
> FOR %%i IN (?) DO ren %%i 0%%i
> FOR %%i IN (??) DO ren %%i 0%%i
> FOR %%i IN (???) DO ren %%i 0%%i
> FOR %%i IN (????) DO ren %%i 0%%i
> FOR %%i IN (?????) DO ren %%i 0%%i
> FOR %%i IN (??????) DO ren %%i 0%%i
> FOR %%i IN (???????) DO ren %%i 0%%i
> ECHO ON

Works perfectly, Tom, thank you!
In this particular case, it is even unnecessary to move index and tag
files into another directory: they use file extensions and your batch thus
doesn't affect them (folder's contents must be re-indexed later, anyway).
Regards, Torsten

Back to the board
Thread view  Mix view  Order
22049 Postings in 2034 Threads, 396 registered users, 244 users online (0 registered, 244 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum