Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fine Points of Using Wildcards in Ren/Copy in DOS

Status
Not open for further replies.

USMA99

Programmer
Oct 12, 2000
85
US
I am supplied a varying number of files with names that are composed of a fixed segment plus an undetermined segment plus an html extension. I need to rename these files in DOS, preserving the undetermined segment (which can be assumed to be unique) while changing the fixed segment to something else and just can't figure it out.

For example:

I'm supplied files such as:

FDG_XZ_99999_variablestring.html
FDG_XZ_99999_anotherstring.html
FDG_XZ_99999_gotchastring.html
FDG_XZ_99999_random.html
FDG_XZ_99999_anothervariablestring.html

etc, where I can predict only the "FDG_XZ_99999_" and ".html" portions

I need to copy and rename them to another location using the names:

12345-1_variablestring.html
12345-1_anotherstring.html
12345-1_gotchastring.html
12345-1_random.html
12345-1_anothervariablestring.html

I've tried various combinations using the * and ? wildcards. Some of what DOESN'T work follows (but I recall it working in the old 8.3 world):

ren FDG_XZ_99999_*.html 12345-1_*.html
ren ?????????????*.html 12345-1_*.html

Can anyone out there get this to work using stock cmd shipped w/ XP Pro?

Thanks in Advance
.



 
Try this - it may work. I'm on a Linux machine right now so I can't try it.
Code:
for %i in (*.html) do ren %i %i:FDG_XZ_99999=12345-1%
 
Unfortunately it yields an error: "The syntax of the command is incorrect."

I'm not completely familiar with what's being done here but it looks like i isn't being set correctly. The command as it is attempting to be executed by the FOR comes out as:

Code:
ren FDG_XZ_99999[varying_portion].html FDG_XZ_99999[varying portion].html:FDG_XZ_99999:FDG_XZ_99999=12345-1
 
OK, now that I've actually tesed it, I see that I had multiple problems. No looping is actually required. In my limited testing, this seems to work.
Code:
:: source directory
set datadir=Z:\[URL unfurl="true"]www\html\test[/URL] [COLOR=green]some original path[/color]
:: destination directory
set newdir=N:\temp\test [COLOR=green]some destination path[/color]
:: original prefix
set origpre=FDG_XZ_99999_
:: new prefix
set newpre=12345-1_
:: copy the files with the new prefix
copy "%datadir%\%origpre%*.html" "%newdir%\%newpre%*.html"
echo Did that work?
pause
cls
You could do this with 1 copy command, but I like to try to make these things modular. You should still have some error checking & if you want to delete the original files, that could be added at the end.
 
This works for me:

Code:
copy FDG_XZ_99999_*.html path\to\other\folder\12345-1_*.html





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top