Windows rename

:

in *NIX OS:

formatting link

Bye Jack

Reply to
jack4747
Loading thread data ...

Hey Rob, your PC clock seems to be a tad off.

Cheers

Reply to
Martin Riddle

Write a script to create a (long) batch file..

Reply to
Robert Baer

I use bash in Linux/MacOS since forever, and have a couple of little tools I use for similar things. One is a command-line tool called "range":

for i in `range 001 120` do mv done

"range" looks for leading zeroes in the first parameter to decide whether to emit them. It also has an optional 3rd parameter for step size.

But for this mass rename, I have a script I call "mved". I no longer use the "bash" version - it was troublesome to correctly escape all possible magic characters in file names. I can provide it if you want. My current version is in Ruby (so you need to have a working Ruby install). This works on Windows too:

mved 99D\* X\*

First and second parameters must both contain one (escaped) asterisk. I keep meaning to extend it to support multiple wildcards.

Here's the implementation:

#! /usr/bin/ruby #

require "getoptlong"

def Usage(code) print "Usage: mved [ options ] pattern1 pattern2\n" + "\t-n:\trename no files, just say what would be done\n" + "\t-v:\tsay what is being done\n" + "\t-f:\toverwrite existing files\n" + "both patterns must contain one wildcard character (* or ?)\n" exit(code) end

$NOCHANGE = false $CAPITALISE_WORDS = false $VERBOSE = false $FORCE = false

optionparser = GetoptLong.new optionparser.set_options( ['--nochange', '-n', GetoptLong::NO_ARGUMENT], ['--capitalise-words', '-c', GetoptLong::NO_ARGUMENT], ['--verbose', '-v', GetoptLong::NO_ARGUMENT], ['--force', '-f', GetoptLong::NO_ARGUMENT], ['--help', '-h', '-?', GetoptLong::NO_ARGUMENT]) begin optionparser.each_option { |option, value| case option when '--nochange' $NOCHANGE = true when '--capitalise-words' $CAPITALISE_WORDS = true when '--verbose' $VERBOSE = true when '--force' $FORCE = true when '--help' Usage(0) end } rescue exit(1) end

if (ARGV.length != 2) Usage(1) end

pattern1 = ARGV.shift pattern2 = ARGV.shift matches = /^([^*?]*)([*?])([^*?]*)$/.match(pattern1) (oldhead, oldwild, oldtail) = matches[1..3] if matches matches = /^([^*?]*)([*?])([^*?]*)$/.match(pattern2) (newhead, newwild, newtail) = matches[1..3] if matches

if (!oldhead || !oldwild || !oldtail || !newhead || !newwild || !newtail || oldwild != newwild) Usage(1) end

copy = oldhead.length..(-oldtail.length-1) #print "wild-range '#{copy}'\n"

# Ruby's Dir[] globbing breaks if the pattern contains a space, sigh. pattern1 = "#{pattern1}" pattern1.gsub!(/[ \[]/, "?") #print "Globbing '#{pattern1}'\n"

files = Dir[pattern1] files.each { |file| # print "file '#{file}'\n" # print "wild-match '#{file[copy]}'\n" newfile = newhead + file[copy] + newtail

if ($CAPITALISE_WORDS) newfile.gsub!(/[a-z]+/) { |match| match.capitalize } end

#print "#{newfile}\n"

if (!$FORCE && File.exists?(newfile)) print "Not overwriting existing file #{newfile}\n" else if ($NOCHANGE or $VERBOSE) print "mv #{file} #{newfile}\n" end if (!$NOCHANGE) File.rename(file, newfile); end end }

Reply to
Clifford Heath

I did the rename in PowerBasic. 40 lines, including comments and whitespace. The working code is

FOR X = 1 TO 100 P$ = DIR$("99D*", 16) ' LOOK UP 99Dxxx TYPE FOLDERS IF P$ "" THEN Q$ = "Z" + MID$(P$, 4) NAME P$ AS Q$ ' RENAME TO Zxxx END IF NEXT

which is 7 lines.

--

John Larkin         Highland Technology, Inc 
picosecond timing   precision measurement  

jlarkin att highlandtechnology dott com 
http://www.highlandtechnology.com
Reply to
John Larkin

Big deal. It's not a general purpose solution.

I can do what you did in a single command line, in the shell (no extra programs needed), and routinely actually do such things.

Reply to
Clifford Heath

Windows command line?

--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

Since when was PowerBasic part of the Windows commandline?

You seem to be stuck in the 1980s, and yet you still call to the Internet to help you to rename a few files... because you're still using 1980's software.

With a Bash commandline you don't need PowerBasic (or Ruby, but I prefer it sometimes).

Time to stop chopping, instead sharpen the axe, don't you think?

Reply to
Clifford Heath

People seem to have missed that you can run linux shell, commands etc *natively* in Win10. No VM.

So, if you like bash and all that comes with it, you don't have to learn a new toolset.

"Microsoft announced support for Ubuntu on Windows 10. This means, developers and administrators will be able to access the powerful command line tools and applications from within Windows. In the past, the only way to do this was by setting up a Virtual Machine with Linux. Not anymore, now you can run a core component of Linux, right on top of Windows."

If you can't beat 'em, join 'em.

formatting link

formatting link

formatting link

formatting link

formatting link

Reply to
Tom Gardner

Without installing a VM yourself. This software package installs the (Hyper-V) VM for you.

Reply to
Rob

Yes and no. Basically the integration with Win10 means that it is easier than via a "traditional" VM.

To launch Bash on Windows 10 and access the local Windows file system, press Windows key + X > Command Prompt (Admin) then type bash at the prompt.

If you want to edit autoexec.bat, then in the bash shell just execute "vi /mnt/c/autoexec.bat"

That's not possible in a "traditional" linux VM running in a Windows host, and that capability directly addresses many of the points being made in this thread.

Reply to
Tom Gardner

Not possible? This has been possible for a long time. Only it required some configuration work, e.g. setting up a local network and configuring mounting of network filesystems. Most VM products already offered this as a pre-configured package under some checkmark like "Access to the host filesystem" that this setup apparently enables by default.

Running "Linux commands" natively in Windows (of course by then they have little to do with Linux anymore and are better called "GNU commands") without a VM has been possible long before VMs were even possible on the PC platform. See the Cygwin environment.

Reply to
Rob

And to think, all I had to do to RE-ACQUIRE this capability was wait 30 years and adopt another "host" OS of dubious quality.

Progress! :>

"Friends don't let friends run Microsoft"

Reply to
Don Y

Den onsdag den 24. august 2016 kl. 10.45.26 UTC+2 skrev Tom Gardner:

or just install cygwin

Reply to
Lasse Langwadt Christensen

It's not - it's a compiler - but I have it. The Windows command-line stuff is pretty broken, and Microsoft will never fix it.

I'd have to install the bash stuff, then learn the bash syntax. Seems like a lot of hassle to rename some files.

Bash is yet another jumble-of-characters weird-syntax scripting language. Fine for full-time code jocks maybe, but I'm an engineer who codes occasionally. The bash reference doc is thousands of lines.

--

John Larkin         Highland Technology, Inc 
picosecond timing   precision measurement  

jlarkin att highlandtechnology dott com 
http://www.highlandtechnology.com
Reply to
John Larkin

This is of course incorrect. The Microsoft fix for the commandline is called PowerShell, it has been available as an optional package for quite some time and now is included in Windows.

Reply to
Rob

PowerShell is not a "fix". It's an interpreted "functional programming"(*) language, provided as a shell.

CMD.exe has many programming features that are additional to what was in MSDOS - but most of them are not widely known. They're also designed even worse than Unix shell, which is really saying something. But the point is that Microsoft has made many attempts to "fix it" before moving to PowerShell.

(*) "Functional" here does not mean "it works", it means that everything is a function. There's a whole culture and mathematics behind this, it's not just a glib expression.

Reply to
Clifford Heath

Yes indeed, people often use only COMMAND.COM syntax in CMD.EXE windows, not knowing that there are extensions.

Reply to
Rob

+1. Before I punted Windows entirely, I had it on every box.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

I haven't read all the replies, but IIRC you recently moved to Win 7. One of the nice things about Win 7 is that they have included powershell as a replacement for cmd, and it's pretty powerfull.

I see that you've written a PB program to rename the directories, but you could have used powershell as follows.

Using explorer navigate to the directory containing the subdirectories. Click on the explorer address bar, clear any text and type powershell_ise. This will start the gui version of powershell, and the current directory will be the directory containing the directories to be renamed. (Type dir to check).

At the command prompt type the following:

get-childitem -filter "*99D*" | rename-item -newname {$_.name -replace '99D', 'Z'} -whatif

This does a 'dry run' of the renaming commands. If everything looks OK rerun the command but omit the -whatif.

That's all there is too it!

Reply to
JM

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.