DOS Rename Question

By jhallstrom ·
I am trying to create a batch file that renames a file and moves it.

When I use the rename function - it does the following


rename shippingConfirmation* shipped*



How do I change this so I get:



This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Well, that's an easy one

by neilb@uk In reply to DOS Rename Question

Put the full-stop in the strings

rename shippingConfirmation.* shipped.*

Collapse -

DOS Rename Question

by jhallstrom In reply to DOS Rename Question

Would that work for this?

rename shippingConfirmation.* shipped.*



How do I change this so I get:



Collapse -

OK, still easy but just the other way round

by neilb@uk In reply to DOS Rename Question

If you want to rename shippingconfirmation_06302010.txt to shipped_06302010.txt then you do:

ren *_06302010.txt Shipped_06302010.txt

If you'd have asked for that the first time, I'd have given you the answer you wanted first time.

Now, if that's STILL not right, tell me EXACTLY what you want to start with and finish with.


Collapse -


by seanferd In reply to DOS Rename Question

ren shippingConfirmation*.* shipped*.*
would be what you are trying to do, but it won't work. (And I still have no idea why you are using a wildcard for the file extension.

rename shippingConfirmation.* shipped.*
results in

It happens because everything after "shipped" is appended by the wilcard rules. That's what shipped* will get you. You have to tell applications exactly what you want, they aren't going to make common sense pattern matching decisions, which require human intelligence.

Collapse -

By following the help for commands.

by seanferd In reply to DOS Rename Question

ren /?
In general, commandname /?

And look up the use of wildcards on windows systems, because that is where your problem is.

ren shippingconfirmation.txt shipped.txt

Don't use wildcards if they could rename more than one file, but I'll guess from your example that you want

ren shippingconfirmation.* shipped.txt

If you don't specify the extension, windows is not going to guess for you. It will just do something weird or fail entirely.

No point in using wildcards in your situation, really. What is it saving you from typing a 3 character extension once? And as I said, you could end up renaming things you don't want renamed, as well as losing files entirely.

Like if you had

and you do

ren shippingconfirmation* shipped.txt

Guess what is going to happen? (You will be prompted for confirmation, giving you the chance to back out. But other commands which allow use of the y switch, and if used, will just let you **** stuff away with no confirmation.

Now, after all that, I'll make another suggestion and say that if you are going to REName then Move a file, you may as well learn to use Xcopy, because that is more flexible, and will let you use the /Y switch so you don't have to confirm. But then you have to DELete the original file.

xcopy C:\dir1\dir2\on order\shippingconfirmation.txt C:\dir1\dir2\fulfilled\shipped.txt

del C:\dir1\dir2\on order\shippingconfirmation.txt

If the CMD prompt is running in the original directory where shippingconfirmation.txt lives (In my example, C:\dir1\dir2\on order\shippingconfirmation.txt), then you don't need to use the full directory path to that file, just the path to the new file in the directory to which it is being moved.

Suit yourself, do it either way, whichever works best for you. You can find a full list of available commands in Help, or at the MS website, and many other places. Every command has help as well, so you can learn how to use it and any available switches it has.

Don't forget to look up wildcards (* and ?) for further usage tips that may suit your needs.

Collapse -


by jhallstrom In reply to DOS Rename Question

Thank you for the information. Our programmers have added one more wrinkle to this change.

It is now shippingconfirmation_20100702114521.txt

and it needs to be renamed to


Collapse -

Have your programmers

by seanferd In reply to Thanks!

take care of you automated thingy here with something other than a batch file.

If you are still going to use a batch file, the same rules still apply.

ren shippingconfirmation_20100702114521.txt shipped.20100702114521.txt


ren *_20100702114521.txt shipped.20100702114521.txt

Related Discussions

Related Forums