wood burning stoves 2.0*
The moose likes General Computing and the fly likes Any DOS programmer here, I need your help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Any DOS programmer here, I need your help." Watch "Any DOS programmer here, I need your help." New topic
Author

Any DOS programmer here, I need your help.

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

I am trying to write a DOS batch file that automatically renames all the files in the current directory into their old filenames prefixed by a 4 digit number. And I don't want AWK.

Any solutions are very welcome .

Regards,
Darya


SCJP, SCJD, SCWCD, SCBCD
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Originally posted by Darya Akbari:
Hi,

I am trying to write a DOS batch file that automatically renames all the files in the current directory into their old filenames prefixed by a 4 digit number. And I don't want AWK.

Any solutions are very welcome .

Regards,
Darya


Assuming 1234 is the four-digit number...


By the way, I'm doing this in a Command Prompt window on Windows XP. Older versions of Windows/DOS may or may not support this use of the FOR command.

Try it.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Ryan,

thanks a lot for this one liner. What when I want the 4 digit number be 0001 0002 ... 9999 (according to i) ?

If we can solve this then it's exactly what I am looking for .

Regards,
Darya
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi guys,

This really isn't the right forum for this discussion, but I can't really think of the right forum, so I'll let it stay for a few more hours. But please, wrap it up. We only want meaningless stuff here

M


Java Regular Expressions
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Max,

please do not delete this topic . If you want move the post, move it to the Programming Diversions forum.

Regards,
Darya
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

General Computing it is.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Originally posted by Darya Akbari:
Hi Ryan,

thanks a lot for this one liner. What when I want the 4 digit number be 0001 0002 ... 9999 (according to i) ?

If we can solve this then it's exactly what I am looking for .

Regards,
Darya


Ok, I think you'll need two bat files.

renamefiles.bat:


dorename.bat


Of course if you have these files in the same directory, they'll get renamed too.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Ryan,

unbelievable that is exactly what I need . You did a great favour to me, thanks so much .

Regards,
Darya
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Ryan,

believe me if I could I did it myself . The script does NOT work when the file names contain SPACES. Is there a way to get around it

Regards,
Darya
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
The spaces cause problems in three places:
- The rename command in dorename.bat.
- The dorename call in renamefiles.bat
- The loop variable in a for /F loop gets only the first "word" off each line.


To fix this, edit renamefiles.bat to be...

and dorename.bat to be...


Mmmm.... DOS 'set' and 'for' voodoo.
[ July 15, 2005: Message edited by: Ryan McGuire ]
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Thanks Ryan,

it's near perfect. Only the & character does not translate. In case you have a quick solution I'm very interested. Anyway you already did a great job for me thanks.

Regards,
Darya
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you have a machine with a DOS window, nowadays you probably have Windows Scripting Host, too. You can replace batch files with JavaScript or VBScript. If you can afford a one-time install, move to a scripting language like Perl, Ruby, REXX, etc. For the last 25 years I thought using batch must be punishment for being really bad in a prior life or something. The only upside is it feels so good when you stop.
[ July 16, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Stan,

I don't like to install anything instead of the batch file. Neither AWK nor anything else like Perl etc. It's all overhead.

When DOS Batch scripting is there why not using it? Ryan did a great job for me and I am very thankful to him.

Regards,
Darya
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Originally posted by Darya Akbari:
Thanks Ryan,

it's near perfect. Only the & character does not translate. In case you have a quick solution I'm very interested. Anyway you already did a great job for me thanks.

Regards,
Darya


What & are you talking about? There aren't any in the .BAT files. If you mean that there is an & in one of the file names, how did you get that?
[ July 18, 2005: Message edited by: Ryan McGuire ]
Sharad Agarwal
Ranch Hand

Joined: Sep 11, 2002
Posts: 167
Originally posted by Darya Akbari:
When DOS Batch scripting is there why not using it?


By the time you have authored some DOS scripts yourself, you will know the answer to that question. Ryan did all the work for you, did you even try to understand the scripts? These forums are intended to help people solve their problems and learn in the process. I would strongly suggest you try to understand Ryan's code - while it does not use abstruse concepts, it is not trivial either.

Further, what he has authored for you is not a DOS script. It will not work in old DOS systems. It is an NT shell script. And both languages (if we can call them that) are chockfull with idiosyncracies and inconsistencies. It is a good tool for small tasks, but as Stan pointed out, it is best avoided if possible.

Check this out.


Alco-Haul: We move spirits.
Demented Deliberations of a Dilettante
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Ryan,

what I mean is, when you have a filename like a & b.txt in your folder and try to start the renamfiles batch file, that this one file a & b.txt will fail.

Regards,
Darya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any DOS programmer here, I need your help.
 
Similar Threads
basic telephone keypad
debug
How to include full file path in io?
running in dos, not command window in windows
Why does ServerSocket stop working after some time?