Featured post
string - Need help with a Windows batch script which should set val of var based on part of a file name -
this not homework - have homework on batch scripting? need automate something. there hard-coded batch script meant run daily systems, , needs work in dynamic fashion. needs input build number, can deduced name of file located @ ... c:\dumplocation\
. not @ batch scripting, , looking batch ninja. if me, code in python myself, cannot expect others install this. powershell not available on every windows computer, batch script lowest common denominator.
this should help: http://www.techsupportforum.com/microsoft-support/windows-xp-support/54848-set-variable-based-output-seach-string-batch.html
here want script do:
dirtolookat = 'c:\dumplocation\' # in location there should single file named # custom_somethingbuild34567client_12345.zip # want extract build number variable effect: buildnumber = '34567' # strings surround build number fixed. # if there more 1 zip file build number in it, # need print warning , pick largest one. # can rest.
the following should well:
http://www.computing.net/answers/programming/batch-string-substitution/12097.html
please let me know if have questions.
assuming custom_somethingbuild
, client_12345.zip
constants, should trick:
@echo off setlocal enabledelayedexpansion rem count of files in directory set /a filecount=0 /f "tokens=* delims= " %%a in ('dir/s/b/a-d c:\dumplocation') ( set /a filecount+=1 ) rem if file count greater or equal 2, warn user if %filecount% gtr 1 echo total number of files in directory is: %filecount% rem if file count less or equal 0, pause , exit if %filecount% leq 0 pause & exit :: each build number, use number if largest number :: in loop, we'll strip out assumed constants, leaving build number. set build= set /a buildnum=0 /f %%a in ('dir /p /b c:\dumplocation') ( set build=%%a set build=!build:custom_somethingbuild=! set build=!build:client_12345.zip=! if !build! gtr !buildnum! set /a buildnum=!build! ) echo greatest build number in directory is: %buildnum% pause
- Get link
- X
- Other Apps
Comments
Post a Comment