| | |
Rename multiple files, changing spacing
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Solved Threads: 0
In Windows XP I have several files in this format: text-### ###.ext
I want to change all of them to this format: text_###-###.ext
So, I need to replace all dashes in the file name with underscores, and replace all spaces with dashes.
I know there are apps for download that do this, but how hard is it to do it myself? Can someone advise if this can be done from the Command Line and, if so, advise how to go about it?
Thanks!
I want to change all of them to this format: text_###-###.ext
So, I need to replace all dashes in the file name with underscores, and replace all spaces with dashes.
I know there are apps for download that do this, but how hard is it to do it myself? Can someone advise if this can be done from the Command Line and, if so, advise how to go about it?
Thanks!
Last edited by Greatoutdoors; Jul 23rd, 2009 at 12:06 pm.
Do you have a useful scripting language installed on your machine (perl, python, ruby, etc)?
Do you have any experience in any of those languages?
> but how hard is it to do it myself?
Somewhere between trivial and impossible.
> Can someone advise if this can be done from the Command Line and, if so, advise how to go about it?
After nearly 30 years, M$ command shell syntax is still a sucking void. Doing anything remotely more interesting that "dir" is an exercise in pointless frustration.
Hence the comment about useful scripting languages....
Do you have any experience in any of those languages?
> but how hard is it to do it myself?
Somewhere between trivial and impossible.
> Can someone advise if this can be done from the Command Line and, if so, advise how to go about it?
After nearly 30 years, M$ command shell syntax is still a sucking void. Doing anything remotely more interesting that "dir" is an exercise in pointless frustration.
Hence the comment about useful scripting languages....
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
Do you have a useful scripting language installed on your machine (perl, python, ruby, etc)?
•
•
•
•
Do you have any experience in any of those languages?
•
•
•
•
Somewhere between trivial and impossible.
•
•
•
•
After nearly 30 years, M$ command shell syntax is still a sucking void. Doing anything remotely more interesting that "dir" is an exercise in pointless frustration. Hence the comment about useful scripting languages....
Well you might be able to do it in Java, don't ask me how.
You'll need some kind of directory class to list the filenames, and maybe even rename them.
You'll also need some kind of string manipulation class to do the substitutions to get from the old filename to the new filename.
Personally, I'd use bash
But feel free to practice the Java approach - it's all good learning when it comes to solving actual problems (rather than bookwork).
You'll need some kind of directory class to list the filenames, and maybe even rename them.
You'll also need some kind of string manipulation class to do the substitutions to get from the old filename to the new filename.
Personally, I'd use bash
for i in text*.ext; do b=`echo $i | sed 's/-/_/g'` b=`echo $b | sed 's/ /-/g'` mv "$i" $b done
But feel free to practice the Java approach - it's all good learning when it comes to solving actual problems (rather than bookwork).
•
•
Join Date: Jul 2009
Posts: 9
Reputation:
Solved Threads: 0
I doubt it can be done with the command-line, but it could be done with the WSH, which comes preinstalled.
Copy the above and paste it into a file with extension '.js', then change the variable dr to your directory's name without an ending backslash -- also remember to escape the backslashes. Then double-click the '.js' file.
var fso,a,s,d,f,t,t0,t1;
var dr;
dr='c:\\mydocu~1\\test';
fso=new ActiveXObject('scripting.filesystemobject');
d=fso.getfolder(dr);
f=new Enumerator(d.files);
t=[];
for(;!f.atEnd();f.moveNext())
{
t0=f.item().name;
if( t0.indexOf(' ')==-1 ) continue;
t1=t0.replace(/-/g,'_').replace(/ /g,'-');
if( t0!=t1 ) t.push([t0,t1]);
}
for(a=0;a<t.length;a++)
{
fso.movefile(dr+'\\'+t[a][0],dr+'\\'+t[a][1]);
}Copy the above and paste it into a file with extension '.js', then change the variable dr to your directory's name without an ending backslash -- also remember to escape the backslashes. Then double-click the '.js' file.
Last edited by prime1999; Jul 26th, 2009 at 10:36 am.
![]() |
Similar Threads
- parsing multiple files in current directory (Perl)
- Repeat a script for multiple files (C++)
- Help get me started, create multiple files from list (Shell Scripting)
- read multiple files (VB.NET)
- reading multiple files in loop (C++)
- Multiple files (C)
- problems writing multiple files (Perl)
- Rename a Series of Files (Windows tips 'n' tweaks)
- How to Rename Multiple Files with Windows Explorer (Windows tips 'n' tweaks)
Other Threads in the Computer Science Forum
- Previous Thread: How to get all possible permutations
- Next Thread: Markov Analysis State Transition diagram
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignment assignmenthelp assignments battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business codebreaker compiler computer computers computerscience computertrackingsoftware connect conversion csc data dataanalysis dataintepretation development dfa dissertation dissertations dissertationthesis dissertationtopic ebook employment energy extensions floatingpoint foreclosure foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea ideas internet ipod itcontracts jobs kindle laser laws linkbait lsmeans mainframes marketing mobileapplication msaccess nano networking news os p2p piracy piratebay principles programming rasterizer sam-being-cute sas science security sex simulation software spying sql stephenfry study supercomputer supercomputing sweden technology textfield turingtest two'scompliment uk virus ww2






