Sign in to follow this  
Followers 0
JustSomeone

Dumb question #1

5 posts in this topic

#1 ·  Posted (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 by JustSomeone

Share this post


Link to post
Share on other sites



loop through that array with filemove


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by JustSomeone

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0