Yzöwl Posted February 16, 2012 Share Posted February 16, 2012 I'd suggest that you also remove the PAUSE now that you're happy with the result. Link to comment Share on other sites More sharing options...
DosCode Posted February 16, 2012 Author Share Posted February 16, 2012 (edited) The pause is good. I will use the script more times, so to be sure the path is OK.Note: The script sometimes leave extra _ in begin of filename and sometimes it removes one more letter (that should not be deleted) from begin of string. The second problem is not often, so not much problem. I don't want to bother you with it. But I have one more question I need to ask, in different thread. Edited February 16, 2012 by DosCode Link to comment Share on other sites More sharing options...
DosCode Posted February 18, 2012 Author Share Posted February 18, 2012 (edited) Right now this happened to me with these files:gen_0_3.pdfgen_2_1.pdfgen_4_1.pdfgen_4_2.pdfso theFOR /F "TOKENS=*" %%# IN ('DIR/B/S/A-D "gen_*.pdf"') DO CALL :RN "%%#" "%%~nx#"GOTO :BREAK:RNSET "_FN=%~2"::ECHO=REN %1 "%_FN:~7%":BREAKcauses they are renamed to.pdf.pdf.pdf.pdf Edited February 18, 2012 by DosCode Link to comment Share on other sites More sharing options...
Yzöwl Posted February 18, 2012 Share Posted February 18, 2012 Those files don't follow your original specification!This may suffice for that scenario:@ECHO OFFSETLOCAL ENABLEEXTENSIONSFOR /F "TOKENS=*" %%# IN ('DIR/B/S/A-D "gen_*.pdf"') DO CALL :RN "%%#" "%%~nx#"GOTO :EOF:RNSET "_FN=%~2"REN %1 "%_FN:~4%" Link to comment Share on other sites More sharing options...
DosCode Posted February 18, 2012 Author Share Posted February 18, 2012 (edited) Does the number "4" at last line mean how the search string is long? I mean gen_ has 4 letters Edited February 18, 2012 by DosCode Link to comment Share on other sites More sharing options...
dencorso Posted February 19, 2012 Share Posted February 19, 2012 With all due respect, DosCode, what you're interested in are "CMD Scripts", not "DOS Batch Files". Your insistence in using "DOS batch" in the titles of your threads is misleading, so please do use "CMD Script" not "DOS Batch" for any new topic you start in the future. Thanks. Link to comment Share on other sites More sharing options...
bphlpt Posted February 19, 2012 Share Posted February 19, 2012 Does the number "4" at last line mean how the search string is long? I mean gen_ has 4 lettersI believe that you have already been referred to the website "ss64.com", but you might want to read this page - http://ss64.com/nt/syntax-substring.html - which explains in detail how to "extract part of a variable (substring)".Cheers and Regards Link to comment Share on other sites More sharing options...
Yzöwl Posted February 19, 2012 Share Posted February 19, 2012 Does the number "4" at last line mean how the search string is long? I mean gen_ has 4 lettersFrom:SET /? %PATH:~10,5%would expand the PATH environment variable, and then use only the 5 characters that begin at the 11th (offset 10) character of the expanded result. If the length is not specified, then it defaults to the remainder of the variable value Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now