Rev- for renaming files according to folder name
Alex Tweedly
alex at tweedly.net
Thu Jun 24 20:09:47 EDT 2010
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
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
repeat for each line L in tAllFiles
if isInteresting(item 1 of L) then
put L & CR after tFiles
end if
end repeat
put the defaultFolder && the number of lines in tAllFiles && the
number of lines in tFioles & 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
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.
>
> Thanks, Kurt_______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
More information about the use-livecode
mailing list