Command Line Utility to manipulate file names

  • Thread starter Thread starter flahmeshess
  • Start date Start date
F

flahmeshess

Is there a utility to manipulate file names ?

eg. Rename a file to all uppercase.
eg. Change the extension of a file.

Thanks.
 
flahmeshess said:
Is there a utility to manipulate file names ?

eg. Rename a file to all uppercase.
eg. Change the extension of a file.

Thanks.

I'm not aware of a tool to change file names to upper
case but you can certainly change the extension of a
file. What exactly are you trying to achieve?
 
I want to do this...

I have 1 file called abc.txt.
I need to append this file to another file called header.TTT to create
another file called ABC-header.TTT


ie copy header.TTT + abc.txt ABC-header.TTT

Note that I also have to manipulate the extension.

I have a number of these abc.txt files with different names, so I need
a way to automate this.

Thanks.
 
flahmeshess said:
I want to do this...

I have 1 file called abc.txt.
I need to append this file to another file called header.TTT to create
another file called ABC-header.TTT


ie copy header.TTT + abc.txt ABC-header.TTT

Note that I also have to manipulate the extension.

I have a number of these abc.txt files with different names, so I need
a way to automate this.

Thanks.

Try this batch file:

@echo off
goto Start
=====================================
Append file2 to file1, then modify the name of file1.

Example: file1=abc.txt
file2=header.TTT
abc-header.TTT=header.TTT + abc.txt

Parameters: %1: name of file1
%2: name of file2
=====================================
:Start
if "%2"=="" echo Parameter missing! & goto :eof

for /F %%a in ('echo %1') do set name1=%%~na
for /F %%a in ('echo %2') do set name2=%%~na
for /F %%a in ('echo %2') do set ext2=%%~xa

echo copy %1 + %2 % name1%-%name2%%ext2%

Remove the word "echo" in the last line to activate the batch file.
Note the the two file names must not include embedded spaces.
 
If you get the unixkit-tiny (google it) this gets very easy.

Make sure that both files are in the same directory.

Go to that directory using unixkit and type:
cat header.TTT abc.txt > ABC-header.TTT

Done.

J
 
But I have to type the names in ... I want to automate this and I need
the utility to pick up the names.
 
I think this could work. Only one thing is that there is a space after
I remove the extension, so the filename is not created correctly.
 
That's probably because you put a space after "xa". Unless
you post your own batch file as an attachment, I have no
way of finding out.
 
Yes. That removed the space... good.

Is there a way to uppercase the filename & extension in the script
(without using the utilities) ?

Thanks !
 
There is, but it's a little tedious. A third-party tool could
probably do it much more elegantly.

@echo off
goto Start
=====================================
Append file2 to file1, then modify the name of file1.

Example: file1=abc.txt
file2=header.TTT
abc-header.TTT=header.TTT + abc.txt

Parameters: %1: name of file1
%2: name of file2
=====================================
:Start
if "%2"=="" echo Parameter missing! & goto :eof

for /F %%a in ('echo %1') do set name1=%%~na
for /F %%a in ('echo %2') do set name2=%%~na
for /F %%a in ('echo %2') do set ext2=%%~xa

set NewName=%name1%-%name2%%ext2%
set NewName=%NewName:a=A%
set NewName=%NewName:b=B%
rem etc. etc.
set NewName=%NewName:z=Z%

echo copy %1 + %2 %NewName%
 
Back
Top