EDAboard.com | EDAboard.de | EDAboard.co.uk | WTWH Media

Windows rename

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - Electronics Design - Windows rename

Goto page Previous  1, 2, 3, ... 17, 18, 19  Next

Artemus
Guest

Tue Aug 23, 2016 7:17 am   



"DemonicTubes" <tlackie_at_gmail.com> wrote in message
news:01318ea8-276c-4230-a9eb-b0dde6017466_at_googlegroups.com...
Quote:
On Monday, August 22, 2016 at 2:01:54 PM UTC-6, John Larkin wrote:
I have a folder with many subdirectories of the form

99D100
99D102
etc

and I want to rename them all as

Z100
Z102
etc.


I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories.


Any suggestions?

There are around 100 to rename, so I guess I could do them one at a
time.


--

John Larkin Highland Technology, Inc
picosecond timing precision measurement

jlarkin att highlandtechnology dott com
http://www.highlandtechnology.com

Maybe something like this:
http://www.bulkrenameutility.co.uk/Download.php


+1

Clifford Heath
Guest

Tue Aug 23, 2016 7:30 am   



On 23/08/16 11:11, rickman wrote:
Quote:
On 8/22/2016 8:51 PM, Don Y wrote:
On 8/22/2016 5:50 PM, Don Y wrote:
On 8/22/2016 5:37 PM, John Larkin wrote:
On Mon, 22 Aug 2016 17:11:06 -0700, Don Y
blockedofcourse_at_foo.invalid> wrote:

On 8/22/2016 1:01 PM, John Larkin wrote:


I have a folder with many subdirectories of the form

99D100
99D102
etc

and I want to rename them all as

Z100
Z102
etc.

I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories.

Any suggestions?

There are around 100 to rename, so I guess I could do them one at a
time.

Write a powerbasic program to do it.

I could, but pragmatically, I'll probably just do them by hand.

In *BSD's shell, it would be something like:

for name in *
do
if [ -d ${name} ]
then
newname=Z${name%99D}

s.b. "name#99D"

mv ${name} ${newname}
fi
done

The embedded conditional only required to limit the
rename operation to directories (in case you also have
files in the same containing directory)

[*lots* of other ways to do it as well]


What exactly is "newname=Z${name#99D}" doing, or more importantly, how
does it work? I realize it is building a new name for the file with a Z
added in place of the 99D. What is the syntax?


<https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion>

John Larkin
Guest

Tue Aug 23, 2016 7:30 am   



On Mon, 22 Aug 2016 17:11:06 -0700, Don Y
<blockedofcourse_at_foo.invalid> wrote:

Quote:
On 8/22/2016 1:01 PM, John Larkin wrote:


I have a folder with many subdirectories of the form

99D100
99D102
etc

and I want to rename them all as

Z100
Z102
etc.

I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories.

Any suggestions?

There are around 100 to rename, so I guess I could do them one at a
time.

Write a powerbasic program to do it.


OK, this works, including folders like 99D336_PWM_Filter



#COMPILE EXE

' rename files in J:\PROTOS

' JL Aug 22, 2016 PBCC v 6.03

#DIM NONE

FUNCTION PBMAIN () AS LONG

DEFINT A-Z

COLOR 15, 1
CLS

FOR X = 1 TO 100

P$ = DIR$("99D*", 16) ' LOOK UP 99Dxxx TYPE FOLDERS

IF P$ <> "" THEN

Q$ = "Z" + MID$(P$, 4)

PRINT P$; " "; Q$
SLEEP 50

NAME P$ AS Q$ ' RENAME TO Zxxx

END IF

NEXT

INPUT "Hit any key...", A$


END FUNCTION




J:\PROTOS contains prototype designs, which could be engineering-only
PC boards, breadboards, experiments, whatever.

Bummer that the Windows REN command is so broken. It does filenames
wrong sometimes, too.


--

John Larkin Highland Technology, Inc

lunatic fringe electronics

Tauno Voipio
Guest

Tue Aug 23, 2016 1:31 pm   



On 22.8.16 23:01, John Larkin wrote:
Quote:


I have a folder with many subdirectories of the form

99D100
99D102
etc

and I want to rename them all as

Z100
Z102
etc.


I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories.


Any suggestions?

There are around 100 to rename, so I guess I could do them one at a
time.


Install MinGW and MSYS (both free), and you get most of the tools
of an UNIX installation, including the Bash shell.

--

-TV


Guest

Tue Aug 23, 2016 1:55 pm   



Il giorno lunedì 22 agosto 2016 22:01:54 UTC+2, John Larkin ha scritto:
Quote:
I have a folder with many subdirectories of the form

99D100
99D102
etc

and I want to rename them all as

Z100
Z102
etc.


I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories.


Any suggestions?


in *NIX OS:
http://www.peteryu.ca/tutorials/shellscripting/batch_rename

Bye Jack

Rob
Guest

Tue Aug 23, 2016 2:23 pm   



rickman <gnuarm_at_gmail.com> wrote:
Quote:
Use a good editor to create a batchfile that does what you want.

E.g. in vi:
!!ls
%s/99D\(.*\)/REN & Z\1/
:w renam.bat
:q

then run renam.bat

Unfortunately most editors in Windows will have more trouble doing
that, but you get the idea.

Recently I needed to do something similar. Seems the wildcarding in the
Windows command window is pretty lame. I had to generate a batch file
with separate lines for each file to be renamed. Codewright didn't have
any trouble with doing the name text replacement.

Still, I'd like to get something that is still live, Codewright has been
bought and sold so many times it's a lame duck. I think you can still
buy it for $350 or so, but there is ZERO support.


I did not check it but I think you can get "vi" for Windows in some
form. Cross-compiled version of vim under cygwin or similar.

However, you will only consider that a "good editor" after you have
spent considerable time training your brain and fingers to issue commands
like the above without having to look in the manual.

It is of course much quicker than using the mouse. I have been using
vi for 30 years, so no issues with that.
(although I now see a small typo in the above... never mind)

Tom Gardner
Guest

Tue Aug 23, 2016 2:32 pm   



On 22/08/16 21:01, John Larkin wrote:
Quote:


I have a folder with many subdirectories of the form

99D100
99D102
etc

and I want to rename them all as

Z100
Z102
etc.


I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories.


Any suggestions?

There are around 100 to rename, so I guess I could do them one at a
time.


Isn't this the kind of thing powershell (MS's scripting
utility) is supposed to do? If not, why not!

NB, I haven't looked at powershell, since I have little
interest nor use for windows nowadays.

Rob
Guest

Tue Aug 23, 2016 2:37 pm   



Tom Gardner <spamjunk_at_blueyonder.co.uk> wrote:
Quote:
Isn't this the kind of thing powershell (MS's scripting
utility) is supposed to do? If not, why not!


My experience is that it is usually a lot more work to code a
script that does something like this, than to generate a batch
file using a text editor that does the same thing.

The examples shown in this thread confirm that.

Besides, when you write a script you need to be very careful
when running it the first time, maybe there is a coding error
that makes you lose all your files (or all but one).

When using the editor method, you can review the result much
more easily before running it.

Of course a script is the way to go when it is a repeatedly occuring
task. For single-shot actions I always use the editor method.

(in Linux it is even easier because you do not have to write the
script to a file, you can just type 1G!Gsh<enter> in vi to execute
the contents of the buffer as a script)

Don Y
Guest

Tue Aug 23, 2016 2:46 pm   



On 8/23/2016 1:32 AM, Tom Gardner wrote:
Quote:
On 22/08/16 21:01, John Larkin wrote:


I have a folder with many subdirectories of the form

99D100
99D102
etc

and I want to rename them all as

Z100
Z102
etc.


I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories.


Any suggestions?

There are around 100 to rename, so I guess I could do them one at a
time.

Isn't this the kind of thing powershell (MS's scripting
utility) is supposed to do? If not, why not!


You can use regex's and capture groups with back-references
(just like with "real" OS's! :> )

But, I suspect (unless you are very comfortable with advanced
regex features) you are more likely to "do damage" as you
try to fabricate the *correct* expression for this.

[I don't think there is a "dry run" capability in PS so
you test your expression with live filesystem contents]

Quote:
NB, I haven't looked at powershell, since I have little
interest nor use for windows nowadays.


Don Y
Guest

Tue Aug 23, 2016 3:06 pm   



On 8/23/2016 1:37 AM, Rob wrote:
Quote:
Tom Gardner <spamjunk_at_blueyonder.co.uk> wrote:
Isn't this the kind of thing powershell (MS's scripting
utility) is supposed to do? If not, why not!

My experience is that it is usually a lot more work to code a
script that does something like this, than to generate a batch
file using a text editor that does the same thing.

The examples shown in this thread confirm that.


I beg to differ. The example /bin/sh script I wrote
can be given a "dry run" trivially:

for name in *
do
if [ -d ${name} ]
then
newname=Z${name#99D}
echo renaming $name as $newname
# mv ${name} ${newname}
fi
done

I've been building (reasonably complete) file hierarchy instances
via a script (i.e., script has to execute as root in order to be
able to access the entire hierarchy so errors can be *painful*!)
and stub each action as above before unleashing it on the live
filesystem.

When you're dealing with hundreds/thousands of files, trying to
create all the "copy" commands explicitly is way too tedious. E.g.
link /dev/[dt]ty0[0-4]
instead of
ln -h /dev/dty00 $DEST/dev/dty00
ln -h /dev/dty01 $DEST/dev/dty01
ln -h /dev/dty02 $DEST/dev/dty02
ln -h /dev/dty03 $DEST/dev/dty03
ln -h /dev/dty04 $DEST/dev/dty04
ln -h /dev/tty00 $DEST/dev/tty00
ln -h /dev/tty01 $DEST/dev/tty01
ln -h /dev/tty02 $DEST/dev/tty02
ln -h /dev/tty03 $DEST/dev/tty03
ln -h /dev/tty04 $DEST/dev/tty04
The "link()" version can easily be stubbed to indicate all
of the commands that *will* be issued without actually doing
anything.

[Imagine making a link of /usr/share/man/* "by hand" ]

Quote:
Besides, when you write a script you need to be very careful
when running it the first time, maybe there is a coding error
that makes you lose all your files (or all but one).

When using the editor method, you can review the result much
more easily before running it.

Of course a script is the way to go when it is a repeatedly occuring
task. For single-shot actions I always use the editor method.

(in Linux it is even easier because you do not have to write the
script to a file, you can just type 1G!Gsh<enter> in vi to execute
the contents of the buffer as a script)


Rob
Guest

Tue Aug 23, 2016 3:21 pm   



Don Y <blockedofcourse_at_foo.invalid> wrote:
Quote:
On 8/23/2016 1:37 AM, Rob wrote:
Tom Gardner <spamjunk_at_blueyonder.co.uk> wrote:
Isn't this the kind of thing powershell (MS's scripting
utility) is supposed to do? If not, why not!

My experience is that it is usually a lot more work to code a
script that does something like this, than to generate a batch
file using a text editor that does the same thing.

The examples shown in this thread confirm that.

I beg to differ. The example /bin/sh script I wrote
can be given a "dry run" trivially:

for name in *
do
if [ -d ${name} ]
then
newname=Z${name#99D}
echo renaming $name as $newname
# mv ${name} ${newname}
fi
done

I've been building (reasonably complete) file hierarchy instances
via a script (i.e., script has to execute as root in order to be
able to access the entire hierarchy so errors can be *painful*!)
and stub each action as above before unleashing it on the live
filesystem.

When you're dealing with hundreds/thousands of files, trying to
create all the "copy" commands explicitly is way too tedious. E.g.
link /dev/[dt]ty0[0-4]
instead of
ln -h /dev/dty00 $DEST/dev/dty00
ln -h /dev/dty01 $DEST/dev/dty01
ln -h /dev/dty02 $DEST/dev/dty02
ln -h /dev/dty03 $DEST/dev/dty03
ln -h /dev/dty04 $DEST/dev/dty04
ln -h /dev/tty00 $DEST/dev/tty00
ln -h /dev/tty01 $DEST/dev/tty01
ln -h /dev/tty02 $DEST/dev/tty02
ln -h /dev/tty03 $DEST/dev/tty03
ln -h /dev/tty04 $DEST/dev/tty04
The "link()" version can easily be stubbed to indicate all
of the commands that *will* be issued without actually doing
anything.


I think it is all MUCH too cumbersome for a single-shot action as
I described earlier. You need to write a script, to run it in
dry mode observing the output, then edit and run it again.

I just do:
vi
!!ls /dev/[dt]ty0[0-4]
:%s!.*!ln -h & DEST/&!
(look at what it is going to do)
1G!Gsh
:q!

Job done.

Don Y
Guest

Tue Aug 23, 2016 3:27 pm   



On 8/23/2016 2:21 AM, Rob wrote:
Quote:
Don Y <blockedofcourse_at_foo.invalid> wrote:
On 8/23/2016 1:37 AM, Rob wrote:
Tom Gardner <spamjunk_at_blueyonder.co.uk> wrote:
Isn't this the kind of thing powershell (MS's scripting
utility) is supposed to do? If not, why not!

My experience is that it is usually a lot more work to code a
script that does something like this, than to generate a batch
file using a text editor that does the same thing.

The examples shown in this thread confirm that.

I beg to differ. The example /bin/sh script I wrote
can be given a "dry run" trivially:

for name in *
do
if [ -d ${name} ]
then
newname=Z${name#99D}
echo renaming $name as $newname
# mv ${name} ${newname}
fi
done

I've been building (reasonably complete) file hierarchy instances
via a script (i.e., script has to execute as root in order to be
able to access the entire hierarchy so errors can be *painful*!)
and stub each action as above before unleashing it on the live
filesystem.

When you're dealing with hundreds/thousands of files, trying to
create all the "copy" commands explicitly is way too tedious. E.g.
link /dev/[dt]ty0[0-4]
instead of
ln -h /dev/dty00 $DEST/dev/dty00
ln -h /dev/dty01 $DEST/dev/dty01
ln -h /dev/dty02 $DEST/dev/dty02
ln -h /dev/dty03 $DEST/dev/dty03
ln -h /dev/dty04 $DEST/dev/dty04
ln -h /dev/tty00 $DEST/dev/tty00
ln -h /dev/tty01 $DEST/dev/tty01
ln -h /dev/tty02 $DEST/dev/tty02
ln -h /dev/tty03 $DEST/dev/tty03
ln -h /dev/tty04 $DEST/dev/tty04
The "link()" version can easily be stubbed to indicate all
of the commands that *will* be issued without actually doing
anything.

I think it is all MUCH too cumbersome for a single-shot action as
I described earlier. You need to write a script, to run it in
dry mode observing the output, then edit and run it again.

I just do:
vi
!!ls /dev/[dt]ty0[0-4]
:%s!.*!ln -h & DEST/&!
(look at what it is going to do)
1G!Gsh
:q!

Job done.


How is that any different from writing a script?
[You're effectively writing a "vi script" -- except
*your* script won't be persistent -- so, when I want to
run it again with $DEST set to "Barney" instead of
"Fred", you'll have to hope you don't make a typo]

Tom Gardner
Guest

Tue Aug 23, 2016 4:38 pm   



On 23/08/16 09:37, Rob wrote:
Quote:
Tom Gardner <spamjunk_at_blueyonder.co.uk> wrote:
Isn't this the kind of thing powershell (MS's scripting
utility) is supposed to do? If not, why not!

My experience is that it is usually a lot more work to code a
script that does something like this, than to generate a batch
file using a text editor that does the same thing.


powershell includes "cmdlets", filtering, globbing and
many more bash/sh/csh/zsh concepts. Hence it /not/ just
a scripting language.

The OP noted
"I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories."
and my comment is in that context.

Whether or not you choose to use scripting/globbing/etc
is a personal choice which does not affect the ability
or otherwise of the cmdlets etc to do what the OP wants.

Jasen Betts
Guest

Tue Aug 23, 2016 4:51 pm   



On 2016-08-22, John Larkin <jjlarkin_at_highlandtechnology.com> wrote:
Quote:


I have a folder with many subdirectories of the form

99D100
99D102
etc

and I want to rename them all as

Z100
Z102
etc.


I've tried variations of the command-line REN command. It renames
files, with wild cards, but I can't make it rename directories.


Any suggestions?


moving the variable part to the left will be tricky, last time I
checked ren couldn't do that.


search or ask on superuser.com, I've done that sort of thing in the
past and forgotten the details other than it started with FOR.

--
This email has not been checked by half-arsed antivirus software

Jasen Betts
Guest

Tue Aug 23, 2016 4:58 pm   



On 2016-08-23, rickman <gnuarm_at_gmail.com> wrote:
Quote:
What exactly is "newname=Z${name#99D}" doing, or more importantly, how
does it work? I realize it is building a new name for the file with a Z
added in place of the 99D. What is the syntax?


variable assignment to variable newname

Z is literal

${name#99D}

takes the content of variable "name" and stripe a leading part that
matches 99D (if present)

--
This email has not been checked by half-arsed antivirus software

Goto page Previous  1, 2, 3, ... 17, 18, 19  Next

elektroda.net NewsGroups Forum Index - Electronics Design - Windows rename

Ask a question - edaboard.com

Arabic version Bulgarian version Catalan version Czech version Danish version German version Greek version English version Spanish version Finnish version French version Hindi version Croatian version Indonesian version Italian version Hebrew version Japanese version Korean version Lithuanian version Latvian version Dutch version Norwegian version Polish version Portuguese version Romanian version Russian version Slovak version Slovenian version Serbian version Swedish version Tagalog version Ukrainian version Vietnamese version Chinese version Turkish version
EDAboard.com map