Change first character in filename
Moderator: DosItHelp
Change first character in filename
Hi,
Need help to replace one character in filename, but only the first.
In Explorer the first character its a square and in DOS its ?. Now I want to change it to O, because I can´t move this file further to another directory with the software I want to use (Opalis Integration server).
The filename look like this
"square"uv10FEX.xml
"square"uv10FOA.xml
"square"uv10REG.xml
..
..
I want it like this
Ouv10FEX.xml
Ouv10FOA.xml
Ouv10REG.xml
..
..
Regards
Benny
Need help to replace one character in filename, but only the first.
In Explorer the first character its a square and in DOS its ?. Now I want to change it to O, because I can´t move this file further to another directory with the software I want to use (Opalis Integration server).
The filename look like this
"square"uv10FEX.xml
"square"uv10FOA.xml
"square"uv10REG.xml
..
..
I want it like this
Ouv10FEX.xml
Ouv10FOA.xml
Ouv10REG.xml
..
..
Regards
Benny
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Change first character in filename
Code: Select all
@echo off&setlocal enabledelayedexpansion
for %%x in ("C:\...\Target Folder\*.xml") do (
set "name=%%~nxx"
ren "%%~dpx?!name:~1!" O!name:~1!
)
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Change first character in filename
here's a vbscript you can use
on the command line
Code: Select all
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder="c:\test"
Set objFolder = objFS.GetFolder(strFolder)
Set objRE = New RegExp
objRE.IgnoreCase = False
objRE.Pattern = "uv\d+[A-Z]{3}.xml"
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) = "xml" Then
strFileName = strFile.Name
Set Matches = objRE.Execute(strFile.Name)
For Each Match in Matches ' Iterate Matches collection.
strFile.Name = "0"&Match
Next
End If
Next
on the command line
Code: Select all
c:\test> cscript //nologo myscript.vbs
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Change first character in filename
orange_batch wrote:Code: Select all
for %%x in ("C:\...\Target Folder\*.xml") do (
this may change other xml files that doesn't have "square".
Re: Change first character in filename
@echo off&setlocal enabledelayedexpansion
for %%x in ("C:\...\Target Folder\*.xml") do (
set "name=%%~nxx"
ren "%%~dpx?!name:~1!" O!name:~1!
)
This script takes all *.xml files, even if they starts with other character, only file that start with "square", shall be changed.
There are a lot of files that have the same beginning except the first character.
for %%x in ("C:\...\Target Folder\*.xml") do (
set "name=%%~nxx"
ren "%%~dpx?!name:~1!" O!name:~1!
)
This script takes all *.xml files, even if they starts with other character, only file that start with "square", shall be changed.
There are a lot of files that have the same beginning except the first character.
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Change first character in filename
Mm sorry I didn't fully test it.
I can't help you if you don't post the actual square character causing this problem. I think it's solvable using some hack with TYPE.
I can't help you if you don't post the actual square character causing this problem. I think it's solvable using some hack with TYPE.
Re: Change first character in filename
Some explanation about this problem.
This sign (Square) is the swedish character Ö. A file has been received in our enviroment on a ftp server. In the translation, it change to this square. I put one filename in here (from Explorer), I hope it will help.
�UV10FEX.xml
This sign (Square) is the swedish character Ö. A file has been received in our enviroment on a ftp server. In the translation, it change to this square. I put one filename in here (from Explorer), I hope it will help.
�UV10FEX.xml
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Change first character in filename
Okay, DOS has serious problems with putting unicode into a batch file, so do this.
Copy this � character. Open Command Prompt (MS-DOS), and type:
Right click the window, paste and press enter.
Save this batch somewhere:
Change the Target Folder, it's similar to before just slightly modified.
Navigate to where the batch is and run it.
Copy this � character. Open Command Prompt (MS-DOS), and type:
Code: Select all
set char=
Right click the window, paste and press enter.
Save this batch somewhere:
Code: Select all
@echo off&setlocal enabledelayedexpansion
for %%x in ("C:\...\Target Folder\%char%*.txt") do (
set "name=%%~nxx"
ren "%%x" O!name:~1!
)
Change the Target Folder, it's similar to before just slightly modified.
Navigate to where the batch is and run it.
Re: Change first character in filename
orange_batch wrote:Okay, DOS has serious problems with putting unicode into a batch file, so do this.
Copy this � character. Open Command Prompt (MS-DOS), and type:Code: Select all
set char=
Right click the window, paste and press enter.
Save this batch somewhere:Code: Select all
@echo off&setlocal enabledelayedexpansion
for %%x in ("C:\...\Target Folder\%char%*.txt") do (
set "name=%%~nxx"
ren "%%x" O!name:~1!
)
Change the Target Folder, it's similar to before just slightly modified.
Navigate to where the batch is and run it.
Thanks !!
Now it works fine, have try other file name to...
Regards Benny