IPB     Il futuro di Tevac dipende da te!  

Benvenuto Visitatore ( Log In | Registrati )

  · · · · · · · · · · · ·
Reply to this topicStart new topic
> [TVC] Rinominare file per dischi FAT32
Tevac
messaggio 4 Feb 2007, 21:43
Messaggio #1


Level 5/11
*****

Gruppo: Forum Staff
Messaggi: 712
Iscritto il: 15-May 03
Da: Internet
Utente Nr.: 4



Segnalazione originale per Tevac di: Marco Coïsson

Qualche giorno fa, su macosxhints, è apparso un interessante AppleScript che può tornare utile a coloro che hanno necessità di salvare file o cartelle su volumi formattati in FAT32; come sapete, infatti, questi volumi hanno forti vincoli sui nomi che si possono dare ai file, avendo una nutrita serie di caratteri proibiti, e alcune regole su quali caratteri possono o non possono essere usati per iniziare il nome di un file.

Questo script, che trovate qui, processa tutti i file o le cartelle che gli vengono date in pasto, e rinomina tutto ciò che vi trova in modo che non vi siano problemi quando si tratterà di copiare il tutto su volumi formattati FAT32. Lo script va copiato e incollato (o riscritto) in Script Editor, quindi salvato come Applicazione. Poi non dovrete fare altro che trascinare sulla sua icona i file o le cartelle da rinominare, e lo script farà tutto lui.

Fate qualche prova prima di affidargli tutto il vostro lavoro: io ho fatto qualche test e sembra funzionare, ma non prendetevela con me se vi brasa tutto l'hard disk. ;-)

Leggi questa segnalazione per intero (con eventuali immagini mancanti) su Tevac
Go to the top of the page
 
+Quote Post
sergiodigiacomo
messaggio 6 Feb 2007, 14:00
Messaggio #2


Level 1/11
*

Gruppo: Members
Messaggi: 3
Iscritto il: 30-May 05
Utente Nr.: 3.840



a me questo script mi da errore:

ERRORE SI SINTASSI, si attendeva "then", ecc. ma è stato trovaro token sconosciuto
Go to the top of the page
 
+Quote Post
poweruser
messaggio 6 Feb 2007, 20:33
Messaggio #3


MacInATopic
Gruppo icone

Gruppo: Team Moderatori
Messaggi: 24.319
Iscritto il: 27-July 03
Da: Maglie (LE)
Utente Nr.: 440



CITAZIONE(sergiodigiacomo @ 6 Feb 2007, 14:00) *
a me questo script mi da errore:

ERRORE SI SINTASSI, si attendeva "then", ecc. ma è stato trovaro token sconosciuto
Bisogna sostituire il punto interrogativo del rigo che dà errore con il simbolo di diverso (≠) o con is not equal to. Ecco il codice corretto.
CODE
property illegalCharacters : {"\\", "/", ":", "*", "?", "\"", "<", ">", "|", "#", "%", "$", ";", "?"} ¬
-- this is the list of characters to substitute from inside the filename
property substituteCharacter : "_" -- this is the character to substitute for the illegal characters
property illegalEnds : {" ", "_", "."} -- this is the list of characters to remove from the start or end of the file
property renameCount : 0 -- count of how many files and folders were renamed
property checkCount : 0 -- count of how many files and folders were checked

on ProcessAFolder(aFolder)
tell application "Finder"
set fileList to every file of aFolder -- grab the files from inside the folder
set folderList to every folder of aFolder -- grab the folders from inside the folder
end tell
my ProcessFiles(fileList) -- process the files
repeat with bFolder in folderList -- loop through the folders
my ProcessAFolder(bFolder) -- recursively go through the folders
my RenameItem(bFolder) -- after checking the folder contents, rename it as well
end repeat
end ProcessAFolder

on open of dropList -- operate on files and folders dropped onto the application
repeat with theItem in dropList -- iterate through the list and call the processing routine
tell application "Finder"
if last character of (theItem as string) is ":" then -- if the item is a folder
my ProcessAFolder(theItem) -- process the folder
my RenameItem(theItem) -- then rename the folder
else
my RenameItem(theItem) -- otherwise rename the file
end if
end tell
end repeat
tell application "Finder" -- make sure the dialog is visible
if renameCount is 0 then -- if nothing was renamed
display dialog "" & checkCount & " items were checked. Nothing was renamed." buttons ("Ok") default button ¬
"Ok" -- alert the user that nothing was renamed
else
display dialog "" & checkCount & " items were checked. " & renameCount & ¬
" item(s) were renamed." buttons ("Ok") default button "Ok" -- otherwise alert the user how many items were renamed
end if
end tell
end open

on run
display dialog "Drag and Drop folders and/or files to rename onto this application" buttons ("Ok") default button ¬
"Ok" -- this is a drag drop, not run
end run

on ProcessFiles(fileList)
repeat with aFile in fileList -- loop through the file list
RenameItem(aFile) -- rename the files
end repeat
end ProcessFiles


on RenameItem(theItem)
set checkCount to checkCount + 1 -- increment the check counter
tell application "Finder"
set theName to name of theItem -- grab just the name of the item
set newName1 to my fixCharacters(theName) -- check for illegal characters throughout the item
set newname2 to my fixEnds(newName1) -- check for illegal characters at the start and end of the item
if theName is not equal to newname2 then -- if the name has been changed
if exists item (((container of theItem) as string) & newname2) then -- check if the new item name already exists
if text -5 thru -1 of newname2 contains "." then -- check for suffix on item name
if text -4 thru -4 of newname2 is "." then -- if is of the form image.jpg
set suffix to text -4 thru -1 of newname2 -- grab the suffix with the period
set newname2 to text 1 thru -5 of newname2 -- grab the first part of the item name
else if text -5 thru -5 of newname2 is "." then -- if is of the form image.jpeg
set suffix to text -5 thru -1 of newname2 -- grab the suffix with the period
set newname2 to text 1 thru -6 of newname2 -- grab the first part of the item name
else if text -3 thru -3 of newname2 is "." then -- if is of the form image.ps
set suffix to text -3 thru -1 of newname2 -- grab the suffix with the period
set newname2 to text 1 thru -4 of newname2 -- grab the first part of the item name
else -- if is of the form image.1
set suffix to text -2 thru -1 of newname2 --grab the suffix with the period
set newname2 to text 1 thru -3 of newname2 -- grab the first part of the item name
end if
else
set suffix to "" -- otherwise there is no suffix
end if
set done to false -- set up our loop exit
set x to 1 -- start our counter
repeat until done
if not (exists item (((container of theItem) as string) & newname2 & x & suffix)) then -- check if the renamed file exists already
set newname2 to newname2 & x & suffix -- add the counter to the filename and add the suffix back on
set done to true -- exit the loop
else
set x to x + 1 -- otherwise increment our counter
end if
if x = 10 then -- if we have reached 10, time to bail anyway
set newname2 to newname2 & x & suffix -- add the counter to the filename and add the suffix back on
set done to true -- exit the loop
end if
end repeat
end if
try -- setup error handling
set name of theItem to newname2 -- try and rename the file to the new name
set renameCount to renameCount + 1 -- increment the rename counter if the rename was successful
on error errMsg number errnum -- if there is an error
set dialogReturn to display dialog "An Error occurred renaming the following item: " & return & (theItem as string) ¬
& return & "to " & newname2 & "." & return & return & "Please go to that file and manually rename it!" & return ¬
& return & errMsg & return & errnum buttons {"Continue?"} default button "Continue?" -- throw an error dialog and continue
end try
end if
end tell
end RenameItem

on fixEnds(theName)
set theName to my fixFirst(theName) -- fix the start of the name
set theName to my fixLast(theName) -- fix the end of the name
return theName -- pass back the (un)changed name
end fixEnds

on fixCharacters(theName)
repeat with x from 1 to (count illegalCharacters) -- loop through the list of illegal characters
if theName contains (item x of illegalCharacters) then -- if this character is in the filename
set oldDelims to AppleScript's text item delimiters -- store the current delimiters
set AppleScript's text item delimiters to (item x of illegalCharacters) -- set the delimiter to the illegal character
set theTextItems to text items of theName -- extract the text without the illegal character as a list of strings
set AppleScript's text item delimiters to substituteCharacter -- set the delimiter to be the substitute character
set theName to theTextItems as text -- change the list of strings back into a single string
set AppleScript's text item delimiters to oldDelims -- change the delimiters back to what they were originally
end if
end repeat
return theName -- pass back the (un)changed name
end fixCharacters

on fixFirst(theName)
set theFirst to first character of theName -- check the first character of the item name
if theFirst is in illegalEnds then -- if the first character is in the illegal list
set theName to text 2 thru -1 of theName -- remove the first character of the name
set theName to my fixFirst(theName) -- make sure we haven't uncovered any more illegals
end if
return theName -- pass back the (un)changed name
end fixFirst

on fixLast(theName)
set theLast to last character of theName -- check the last character of the item name
if theLast is in illegalEnds then -- if the last character is in the illegal list
set theName to text 1 thru -2 of theName -- remove the last character of the name
set theName to my fixLast(theName) -- make sure we haven't uncovered any more illegals
end if
return theName -- pass back the (un)changed name
end fixLast

Ciao
Paolo


--------------------
Paolo Portaluri

guru, n: A computer owner who can read the manual.
Go to the top of the page
 
+Quote Post
murpy
messaggio 1 Dec 2008, 15:05
Messaggio #4


Level 1/11
*

Gruppo: Forum User
Messaggi: 6
Iscritto il: 8-January 07
Utente Nr.: 7.615



ciao, stavo provando questo script che mi sarebbe stato molto utile ma ho notato che si limita a sostituire i caretteri non-validi ma non si preoccupa di troncare i nomi troppo lunghi. qualcuno ha idea di come "estenderlo" per coprire anche quest'altra funzionalità?

grazie

ciao
Go to the top of the page
 
+Quote Post
chebfarid
messaggio 1 Dec 2008, 15:23
Messaggio #5


Level 8/11
********

Gruppo: Team Moderatori
Messaggi: 3.896
Iscritto il: 11-July 03
Da: Milano
Utente Nr.: 395



Non ho mai provato questo script e in questo momento scrivo pure da un PC Win, ma la riga dello script che crea il nuovo nome è questa:
CODICE
set newname2 to newname2 & x & suffix -- add the counter to the filename and add the suffix back on

Non mi ricordo nemmeno il formato canonico per un file su dischi FAT32: 8+3 è corretto?
Assumendo che sia così dovrebbe funzionare una cosa del genere:
CODICE
if count of newname2 > 8 then
set newname2 to (text 1 thru 8 of newname2)
else
set newname2 to newname2
end if
set newname2 to newname2 & x & suffix -- add the counter to the filename and add the suffix back on

Questo blocco sostituisce la riga citata sopra.
Come detto, non l'ho testato, meglio farsi una copia di sicurezza dei file in questione.

Buon scripting
Farid


--------------------
Abends lustig, morgens triste
das ist Leben von Artiste
Go to the top of the page
 
+Quote Post
murpy
messaggio 1 Dec 2008, 15:35
Messaggio #6


Level 1/11
*

Gruppo: Forum User
Messaggi: 6
Iscritto il: 8-January 07
Utente Nr.: 7.615



grazie Farid,
ma prima di mettermi a trappolare con applescript ho dato uno sguardo al post su macosxhints ed ho scoperto che lo stesso autore ha aggiornato lo script di partenza per ovviare anche al problema della lunghezza dei caratteri.
Lo script "completo" si trova qui:
Updated script now with name shortening

ciao
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 

Collapse

> 

    Titolo discussione Risposte Autore discussione Visite Ultima azione
No New Posts   0 Tevac 19 Oggi, 02:27
Ultimo messaggio di: Tevac
No New Posts   1 cicciobarbara 32 Ieri, 20:50
Ultimo messaggio di: chebfarid
No New Posts   5 TevacPhoto 220 29 December 2008 - 14:47
Ultimo messaggio di: macfilobur
No new   9 Giuseppe Mazza 164 28 December 2008 - 13:19
Ultimo messaggio di: Giuseppe Mazza
No New Posts   1 augustovestri 53 27 December 2008 - 20:03
Ultimo messaggio di: Baco
No new   155 Italo 4.483 21 December 2008 - 22:24
Ultimo messaggio di: francesco59
No New Posts   4 mmarini 132 16 December 2008 - 20:31
Ultimo messaggio di: mmarini
No New Posts   4 Sebastiano Ceppi 224 13 December 2008 - 17:19
Ultimo messaggio di: majortom
No New Posts   5 bacillino80 188 13 December 2008 - 16:37
Ultimo messaggio di: Pasqual
No New Posts   1 fede86 92 9 December 2008 - 17:54
Ultimo messaggio di: chebfarid
No new   32 Biba 1.403 1 December 2008 - 16:43
Ultimo messaggio di: Biba
No New Posts   5 area00 124 26 November 2008 - 10:48
Ultimo messaggio di: sirguich_

Modalità di visualizzazione: Normale · Passa a: Lineare · Passa a: Outline


RSS Versione Lo-Fi Oggi è il: 8 January 2009 - 17:01
IP.Board Skin Developed By Creative Networks