JustSomeone Posted June 3, 2014 Share Posted June 3, 2014 (edited) Hello again How i can get a list of files in folder x (this i can do) , trim the last 10 symbols of the name (somefile_page_0001.TIF) and rename the file to page_0001_somefile.TIF and do this for all the files in the current folder x. part of the logic is i can put all the files to an array, but then how to manipulate the names and rename the files. they will be always .tif / .TIF and they will always contain _page_000x before the file extension. Halp pliz :0) Edited June 3, 2014 by JustSomeone Link to comment Share on other sites More sharing options...
iamtheky Posted June 3, 2014 Share Posted June 3, 2014 loop through that array with filemove ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Solution JustSomeone Posted June 3, 2014 Author Solution Share Posted June 3, 2014 (edited) I don't understand the trim part, where i get the name, convert it to string, change it then rename the file. can i get an example of the renaming part please ? EDIT i made it ConsoleWrite(" Source filename : " & $zFileName &@CRLF) Local $sFileNoext = StringTrimRight($zFileName,4) ;remove the file extension and keep the rest of the name Local $sFilePattern = StringTrimRight($zFileName,14) ; remove the file extension and the _page_000x pattern Local $sNameLen = StringLen($sFileNoext) ; calculate the lenght of the string Local $sNameLen1 = $sNameLen - 1 ; reduce count with 1 local $sName0or1 = StringTrimLeft($sFileNoext,$sNameLen1);get the page number by its name ConsoleWrite("Destination name : " & $sName0or1 & $sFilePattern & ".tif" &@CRLF) Edited June 3, 2014 by JustSomeone Link to comment Share on other sites More sharing options...
somdcomputerguy Posted June 3, 2014 Share Posted June 3, 2014 Here's another way Local $Filename = "somefile_page_0001.TIF", $aFilename = StringSplit($Filename, "_") ConsoleWrite("original filename - " & $Filename & @LF & "now the filename is - " & $aFilename[2] & "_" & StringTrimRight($aFilename[3], 4) & "_" & $aFilename[1] & ".TIF" & @LF) - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
MHz Posted June 3, 2014 Share Posted June 3, 2014 i made it Well done. If you not scared of PCRE, then perhaps this could help $sSource = 'somefile_page_0001.TIF' $sDestination = _MyRename($sSource) MsgBox(0, '$sDestination', $sDestination) Func _MyRename($sFilename) ; capture any chars, then _page_000x, and then .tif. return group 1 appended to group 3 Return StringRegExpReplace($sFilename, '(?i)(.+)(_page_\d{4})(\.tif)', '\1\3') EndFunc 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