• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Any DOS programmer here, I need your help.

 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Max,

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

Regards,
Darya
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
General Computing it is.
 
Ryan McGuire
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ryan,

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

Regards,
Darya
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic