|
Answer» i have files and i want them renames as such: p000001.gif -> p1.gif p000002.gif -> p2.gif p000003.gif -> p3.gif p000004.gif -> p4.gif p000005.gif -> p5.gif p000006.gif -> p6.gif p000007.gif -> p7.gif p000008.gif -> p8.gif p000009.gif -> p9.gif p000010.gif -> p10.gif does anybody have a batch file or dos command (better) to do it? Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject") strFolder = "c:\test" Set objFolder = objFS.GetFolder(strFolder) For Each strFile In objFolder.Files If objFS.GetExtensionName(strFile) = "gif" Then strFileName = strFile.Name strNum = Mid(strFileName,2,6) strNum = strip(strNum) strNewFileName = Mid(strFileName,1,1) & strNum & Mid(strFileName,8) strFile.Name strNewFileName End If Next
Function strip(str) s="" For i=1 To LEN(str) If Mid(str,i,1) <> "0" Then s=s&Mid(str,i) Exit For End If Next strip=s End Function
Code: [Select]c:\test> cscript /nologo myscript.vbs didnt work :: it didnt change anything oh wait i didnt notice it the first time: there was an error message Microsoft VBScript runtime error object does no support this property or method: 'strFile.Name'the problem area is Code: [Select] strFile.Name strNewFileName i will leave it to you to find out. Hint: an OPERATOR is missingi tried = but it didnt work i DONT LIKE vb or vb script so i dont know never mind i got it -- there was a conflicting file in thereHere is a site that has lots of string manipulation for DOS. http://www.dostips.com/DtTipsStringManipulation.php
From that site an example to replace a word in a LINE of text. Code: [Select]set str=teh cat in teh hat echo.%str% set str=%str:teh=the% echo.%str% DOS Script Ouput Quote teh cat in teh hat the cat in the hat If you can understand that, then you can get rid of leading zeros by recursion. Or iteration.
Quote from: Geek-9pm on September 06, 2009, 07:43:31 PMHere is a site that has lots of string manipulation for DOS. http://www.dostips.com/DtTipsStringManipulation.php
From that site an example to replace a word in a line of text. Code: [Select]set str=teh cat in teh hat echo.%str% set str=%str:teh=the% echo.%str% DOS Script Ouput If you can understand that, then you can get rid of leading zeros by recursion. Or iteration.
thats neat
http://www.robvanderwoude.com/battech_leadingzero.php
Code: [Select]:Loop IF "%Var:~0,1%"=="0" ( SET Var=%Var:~1% GOTO Loop )
|