Another problem with renaming files...

  • Thread starter mathewsdw@sbcglobal.net
  • Start date
Status
Not open for further replies.
M

mathewsdw@sbcglobal.net

Guest
Background: I download files from an external site (that I have no control over) whose file names are constructed in a way that I absolutely hate! Among several issues is the fact that the file names contain underscores rather than blanks (i.e. This_is_a_sample_file_name.ext). Since I have gotten (and continue to get) a _lot_ of files from this site, I am trying to write a batch file that will rename them into a format that I don't absolutely despise automagically. (The complete set of renaming rules is well defined.) I was having problems with open parenthesis, but I got the solution from this site (Thanks again for that!). So the next problem is that I am unable to process file names that contain commas. (Specifically, %@Index[filename,_], for example, doesn't work if the file name contains comma(s). So the question is: is there a workaround of some kind for this problem? (I can't use the escape character ("^") in the file name variable because I am not building the original file names that I am trying to change.) Thanks in advance for any help you can give me!
 
May 29, 2008
36
0
For commas I would try %@replace[^,, ,%filename]. This would replace commas in
%filename with a blank.

Dennis
 

samintz

Scott Mintz
May 20, 2008
1,495
16
Solon, OH, USA
I would rename the files first and then do your operations on them. A
*lot* of hassle can be avoided by various combinations of SETDOS /X. Look
up the help on SETDOS /X and see if that fixes your issue.

I created a strangely named file and was able to rename it using @REPLACE
to replace the commas with underscores.

[C:\Temp\foo] >"this,is,a(funky)_file"

[C:\Temp\foo] dir

Volume in drive C is unlabeled Serial number is 5013:eee9
Directory of C:\Temp\foo\*

6/18/2009 11:16 <DIR> .
6/18/2009 11:16 <DIR> ..
6/18/2009 11:16 0 this,is,a(funky)_file
0 bytes in 1 file and 2 dirs
63,793,283,072 bytes free

[C:\Temp\foo] ren "this,is,a(funky)_file"
%@replace[^,,_,"this,is,a(funky)_file"]
C:\Temp\foo\this,is,a(funky)_file -> C:\Temp\foo\this_is_a(funky)_file
1 file renamed

Here's another example:
for %f in (*) do ren "%f" %@replace[^,, ,"%f"]

I couldn't get delayed expansion to work properly. Rex or someone - can
you explain why this doesn't work?

[C:\Temp\foo] dir

Volume in drive C is unlabeled Serial number is 5013:eee9
Directory of C:\Temp\foo\*

6/18/2009 11:36 <DIR> .
6/18/2009 11:36 <DIR> ..
6/18/2009 11:35 0 this,is,a(funky)_file
0 bytes in 1 file and 2 dirs
63,793,344,512 bytes free

[C:\Temp\foo] ren * %%@replace[^,,_,"*"]
C:\Temp\foo\this,is,a(funky)_file -> C:\Temp\foo\this,is,a(funky)_file]
TCC: (Sys) The system cannot find the file specified.
"C:\Temp\foo\%@replace["
TCC: (Sys) The system cannot find the file specified.
"C:\Temp\foo\_"
1 file renamed

[C:\Temp\foo] dir

Volume in drive C is unlabeled Serial number is 5013:eee9
Directory of C:\Temp\foo\*

6/18/2009 11:36 <DIR> .
6/18/2009 11:36 <DIR> ..
6/18/2009 11:35 0 this,is,a(funky)_file]
0 bytes in 1 file and 2 dirs
63,793,340,416 bytes free


Notice the commas were not replaced and a close bracket was appended to
the name.

-Scott

"mathewsdw@sbcglobal.net" <> wrote on 06/18/2009
01:44:26 AM:


> Background: I download files from an external site (that I have no
> control over) whose file names are constructed in a way that I
> absolutely *hate*! Among several issues is the fact that the file
> names contain underscores rather than blanks (i.e.
> This_is_a_sample_file_name.ext). Since I have gotten (and continue
> to get) a _lot_ of files from this site, I am *trying* to write a
> batch file that will rename them into a format that I *don't*
> absolutely despise automagically. (The complete set of renaming
> rules is well defined.) I *was* having problems with open
> parenthesis, but I got the solution from this site (Thanks again for
> that!). So the *next* problem is that I am unable to process file
> names that contain commas. (Specifically, %@Index[filename,_], for
> example, doesn't work if the file name contains comma(s). So the
> question is: is there a workaround of some kind for this problem?
> (I can't use the escape character ("^") in the file name variable
> because I am not !
> building the original file names that I am trying to change.)
> Thanks in advance for any help you can give me!
>
>
>
>
 
M

mathewsdw@sbcglobal.net

Guest
Thanks, guys! I changed the commas to question marks (which, as far as I know, can not appear in "valid" filenames) using the @Replace function as you suggested (I did not know the @Replace function even existed), and, when I was otherwise done manipulating the file names, I changed the question marks back to commas (I knew how to do that which is a good thing because @Replace doesn't seem to work in this instance...).
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
vefatica Another popup problem Support 10
vefatica Another problem with build 22. Support 3
M Take Command 18, migrating to another machine, license problem. Support 1
fishman@panix.com Another Problem with The Installer Support 1
jdanielp Cannot step into and/or call another .bat file when debugging .bat file Support 2
S How to? Runs start /w in invisible mode OR run program after exit of another one Support 3
G Press on another Window Support 24
M Another possibly strange remote registry issue Support 5
Patulus Yet another thread on CMD compatibility Support 16
MickeyF Another TPIPE question Support 6
vefatica Another installer thingy Support 1
vefatica Another @EVERYTHING question Support 4
C Touch command — I Need to touch matching files in another directory. Support 5
M Another "What is wrong?" Support 8
Bill de Haan Another installation is in progress Support 6
Charles Dye Another modest proposal Support 4
Dan Glynhampton Documentation v15 help: Another mailto: link oddity Support 0
M WAD Another weird copy command errror... Support 2
M Yet another strange something re something called "@TCONVERT" Support 8
Charles Dye Documentation Another help nit Support 3
K_Meinhard Documentation Another installer nit Support 1
ehab aboudaya How to? change ALT-F6 to another key Support 1
A How to? Pass output from ffind to another command in a BTM file Support 5
M Another simple question re. Take Command/TCC window witdth in characters... Support 16
Q TCC: (Sys) The process cannot access the file because it is being used by another process. Support 0
M Another bit of weirdness.... Support 0
S MOVE from FTP directory to another FTP directory - bug?? Support 2
vefatica Another debugger observation Support 12
vefatica Another DO /L question Support 1
M Another TCMD "crash" situation... Support 2
S Need help to execute TCC commands on another system Support 6
B TCC doesn't run using another user Support 2
H Another multiple FTP password prompt issue Support 2
Peter Bratton Another little bug? Support 1
nikbackm Another HISTORY dialog issue Support 0
vefatica Another help nit Support 12
S Another 4NT 8.02 vs TCC 9.02 diff - MOVE command Support 3
p.f.moore Running another batch file without CALL Support 7
Dick Johnson Weird Color Problem Support 8
fishman@panix.com Problem with 27.15 Support 2
M Problem with VSDevCmd.bat in VS 16.7.3 Support 0
R Problem with @INT[ value] in V26 Support 9
M Selecting test "off by one" problem in Take command Support 4
Alpengreis UTF-8 problem in TCC related to Python Support 7
K_Meinhard Small problem in german IDE 26 Support 3
B Problem with color in nested shells Support 1
Joe Caverly Problem creating and switching to a DESKTOP Support 9
Alpengreis ffind dialog (/W) problem Support 4
Alpengreis [TCMD v25.00.24] Small space problem with the DE translation in Prefs-GUI Support 1
Alpengreis [TCMD v25.00.24] Problem with copy and paste and the # char via mouse in TCC Support 6

Similar threads