Rev- for renaming files according to folder name
Jim Ault
jimaultwins at yahoo.com
Fri Jun 25 01:23:24 EDT 2010
A few tweaks that make the code a few lines shorter.
On Jun 24, 2010, at 5:09 PM, Alex Tweedly wrote:
> Sounds a perfect task for Rev. Here is a scrit I had lying around
> that did something similar - modified to suit, tested VERY minimally
> and with some debugging left in place :-)
>
> Basically - modified by the tips of my fingers, so check it
> carefully before using .... and watch for line wrap ..
>
> local sCount
>
> on mouseUp
> set the defaultFolder to "/Users/alextweedly"
> put empty into field "F"
> put the folders into tFolders
>
* filter tFolders without ".*"
> repeat for each line F in tFolders
> --* if the first char of F is not "." then
> doOneFolder F
> --* end if
> end repeat
> end mouseUp
>
> on doOneFolder pFolder
> put the defaultFolder into tWhere
> set the defaultFolder to pFolder
> put "do" && pFolder && the defaultFolder && the number of lines in
> tAllFiles && the number of lines in tFiles & CR after field "F"
> put 0 into sCount
> put the detailed files into tAllFiles
* filter tAllFiles without ".*"
> repeat for each line L in tAllFiles
> ---* if isInteresting(item 1 of L) then
* if (char -4 to -1 of L is in ".png .jpg .bmp .doc") then
> put L & CR after tFiles
> end if
> end repeat
> put the defaultFolder && the number of lines in tAllFiles && the
> number of lines in tFiles & CR after field "F"
> sort lines of tFiles by item 4 of each -- is this same item on Win ?
> repeat for each line L in tFiles
> doOneFile pFolder, URLDecode(item 1 of L)
> end repeat
> set the defaultFolder to tWhere
>
> end doOneFolder
>
---- don't need the isInteresting() function
---- added one line and modified one line above
> function isInteresting pFile
> --put "try " && pFile & CR after field "F"
> if char 1 of pFile is "." then
> -- put "nope" & CR after field "F"
> return false
> end if
> if pFile contains ".png" then return true
> if pFile contains ".jpg" then return true
> if pFile contains ".bmp" then return true
> if pFile contains ".doc" then return true
> --put "Nope" & CR after field "F"
> return false
> end isInteresting
>
> on doOneFile pFolder, pFile
> add 1 to sCount
> set the itemDelimiter to "."
> put "rename" && pFolder && pFile && "-->" && \
> format("%s%05d.%s", pFolder, sCount, item -1 of pFile) & CR
> after field "F"
> end doOneFile
>
>
>
> -- Alex.
>
> On 24/06/2010 17:59, Kurt Kaufman wrote:
>> I think that the following sounds like a good task for Rev; just
>> want to make sure:
>> OS: WinXP SP3
>> About 1300 folders at same level; each folder with 10-200 files of
>> type jpg,png,bmp,doc.
>>
>> Would rename every file within folder to the name of that folder
>> plus incremented number, i.e.
>> name_of_folder00001.jpg
>> followed by, potentially,
>> name_of_folder00002.doc.
>>
>> Important: The files would be renamed and sorted by creation date
>> only, so that
>> name_of_folder00001.jpg
>> would be newer than
>> name_of_folder00002.doc.
>>
>> I'm pretty sure that I could apply the programming WD-40 to my
>> brain and remember how to do this (would be a good exercise, also),
>> but would appreciate any tips, warnings, etc.
>>
Jim Ault
Las Vegas
More information about the use-livecode
mailing list