Saved Bookmarks
| 1. |
Solve : converting hex filenames to decimal in batch file? |
|
Answer» Hello All, Hello All, I'm not aware of any batch command that can do this. You can do this is VBScript HOWEVER: Code: [Select]Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell = WScript.CreateObject("WScript.Shell") Set f = fso.GetFolder("c:\temp") 'change directory here Set fc = f.Files For Each FS In fc fname = fso.GetBaseName(fs) fext = fso.GetExtensionName(fs) newName = CLng("&H" & fname) & "." & fext fs.Name = newName Next Save with a VBS extension and run from the command line as cscript scriptname.vbs You may have to change the directory name. Good luck. Thank you Sidewinder. batch can do this directly. set /a TREATS numerical strings beginning 0 as octal (pitfall for the unwary!), and those beginning 0x as hexadecimal. Code: [Select]@echo off setlocal enabledelayedexpansion echo abc > 0000.txt echo def > 1000.txt echo ghi > aaaa.txt echo jkl > 000f.txt echo mno > 00ff.txt echo pqr > 0fff.txt echo stu > ffff.txt echo vwx > aef2.txt for /f %%H in ('dir /on /b *.txt') do ( set hexstring=%%~nH set extension=%%~xH set /a decstring=0x!hexstring! set pad= if !decstring! leq 9999 set pad=0!pad! if !decstring! leq 999 set pad=0!pad! if !decstring! leq 99 set pad=0!pad! if !decstring! leq 9 set pad=0!pad! set decstring=!pad!!decstring! echo !hexstring!!extension! =^> !decstring!!extension! ) Code: [Select]0000.txt => 00000.txt 000f.txt => 00015.txt 00ff.txt => 00255.txt 0fff.txt => 04095.txt 1000.txt => 04096.txt aaaa.txt => 43690.txt aef2.txt => 44786.txt ffff.txt => 65535.txt |
|