b3ta.com qotw
You are not logged in. Login or Signup
Home » Question of the Week » Redundant technology » Post 953638 | Search
This is a question Redundant technology

Music on vinyl records, mobile phones the size of house bricks and pornography printed on paper. What hideously out of date stuff do you still use?

Thanks to boozehound for the suggestion

(, Thu 4 Nov 2010, 12:44)
Pages: Latest, 14, 13, 12, 11, 10, ... 1

« Go Back | See The Full Thread


But.. that would have renamed all the files from 50MMGD to 100MGD (the last 0 in 100 would ovewrite the first M in MMGD. You need to add a buffer character to make up for the additional 0.

ren 10*.* to 100*.*
renames 50MMGD to 100MGD

So you need to stick an x on the front like this:

setlocal enabledelayedexpansion
rem this ranmes 50MMGD to x50MMGD making space for the extra character.
for %%a in (*) do rename %%a x%%a
ren x10*.* 100*.*

OMG .. I'm a huge nerd. And if it were me, I would have used len, and made sure to only rename if the first three characters were [0-9].

I'm scaring myself as I write this.
(, Thu 4 Nov 2010, 17:55, 2 replies)

you may need to write him a batch file to fix that :)
(, Thu 4 Nov 2010, 18:25, closed)
I don't follow your logic.
The asterisk replaces any number of characters so DOS (and, I think, BASH) would preserve the matched part and replace the non-matched.
(, Thu 4 Nov 2010, 18:34, closed)

X:\dir
Volume in drive X is System
Volume Serial Number is 1682-2120

Directory of X:\

2010-11-04 14:35 PM DIR .
2010-11-04 14:35 PM DIR ..
2010-11-04 13:53 PM 7 10test.txt
1 File(s) 7 bytes
2 Dir(s) 56,501,731,328 bytes free

X:\ren 10* 100*

X:\dir
Volume in drive X is System
Volume Serial Number is 1682-2120

Directory of X:\

2010-11-04 14:36 PM DIR .
2010-11-04 14:36 PM DIR ..
2010-11-04 13:53 PM 7 100est.txt
1 File(s) 7 bytes
2 Dir(s) 56,501,727,232 bytes free

X:\

I don't really understand how to word it, but it seems the * doesn't really hold the value, it just means anything including nothing. My experiments using ? instead of * yeilded the same results. I've always buffered them out. and I can't seem to put greater-than signs in this forum. Probably to stop stilly folks from playing with HTML.

I guess 'they' had to pick a awy to work that query. ren 10* 100* could also have meant append: like 10foo becomes 10010foo since * means any file. Or it could mean ren 10foo to 100[undefined], or rename 10foo to first hit on *. So reanme it could rename all files to 10foo (except rename won't allow that)... and so on. * is not like $1 in perl. it is $1 right ... ?
(, Thu 4 Nov 2010, 18:39, closed)

Am I breaking rules by chatting bout this? Please don't ban me, I'm just feeling chatty.

reaname 10* to 100* in a command shell means:
Take the first file that begins with with 10 and ends with anything, then make it begin with 100 and end it with what was already there. Overwriting as you go.

The shell isn't reaplacing 10 with 100, it is putting 100 at the beginning of the file, ovewriting what is already there. I can't remember bash so well, but I it works similar. Something like:
for f in 10*; mv $f 100`echo "$f" | cut 1-2`; done

Get a list of files 'f' that begins with 10, move $f to 100$f(with the first 2 characters (hopefully 10) cut off)

Don't copy and paste that into bash, I'm on a windows box now. I'm working with a very old manbrain.
(, Thu 4 Nov 2010, 19:01, closed)
On some csh shells you get rename:
rename 50 100 50*

Job done. DOS makes me feel a bit sick. It's like a proper shell's crippled cousin
(, Thu 4 Nov 2010, 20:26, closed)
Smiles...
All these replies have actually been interesting to read! As someone who still plays with command prompts and writes the odd script at work I love stuff like this!
(, Thu 4 Nov 2010, 23:48, closed)

/bin/csh

% ls
50test.txt
% rename 50 100 50*
% ls
50test.txt

didn't work.

I think (don't know) that 'rename' is a PERL script that's unlikely to be influenced much by the shell it's running on.

however rename does accept perl regexps... so you could use:
rename 's/^50/100/' 50*

Better than my messy sub routine.
(Just confirmed on my Gentoo system)
(, Fri 5 Nov 2010, 3:15, closed)
Sorry, you are right of course.
I forgot thar you can't rename like that because it only uses the * for pattern matching and the name of the file minus the matched but is not stored anywhere.
(, Fri 5 Nov 2010, 17:21, closed)

« Go Back | See The Full Thread

Pages: Latest, 14, 13, 12, 11, 10, ... 1