Non pas de possibilité...est-il possible de prévoir chiffre et texte dans le script
Là je ne comprend pas !il me double les infos du fichier parfois
Et toujours non !est-il possible d'avoir le script avec une interpretation en chiffre ?
set resultat to choose folder with prompt "Sélectionner le dossier pour les resultats"
set pdf1 to choose folder with prompt "Sélectionner le premier fichier pour la recherche"
set pdf1 to pdf1 as string
set pdf1 to quoted form of POSIX path of pdf1 as string
set pdf2 to choose folder with prompt "Sélectionner le deuxième dossier pour la recherche"
set pdf2 to pdf2 as string
set pdf2 to quoted form of POSIX path of pdf2 as string
set bureau to POSIX path of (path to desktop folder as text)
set commande to "find " & pdf1 & " -maxdepth 1 -name '*.pdf' > " & bureau & "liste.txt"
do shell script commande
set commande to "find " & pdf2 & " -maxdepth 1 -name '*.pdf' > " & bureau & "liste1.txt"
do shell script commande
set commande to "cat " & bureau & "liste1.txt >> " & bureau & "liste.txt"
do shell script commande
do shell script "rm " & bureau & "liste1.txt"
set laligne to 2
set drapeau to 0
repeat
set liste1 to ""
set nb1 to 0
tell application "Microsoft Excel"
activate
set lefichier to value of range ("a" & laligne)
set materiel to value of range ("b" & laligne)
set largeur to value of range ("d" & laligne)
set hauteur to value of range ("e" & laligne)
set recto to value of range ("i" & laligne)
set QT to value of range ("m" & laligne)
end tell
if lefichier is "" then
exit repeat
end if
set newnom to "_" & materiel & "_" & largeur & "_" & hauteur & "_" & recto & "_" & QT & "ex"
--Cherche le fichier
set commande to "grep " & lefichier & " " & bureau & "liste.txt"
try
set liste1 to do shell script commande
on error
set liste1 to ""
end try
set AppleScript's text item delimiters to {return}
set nb1 to count text item of liste1
if nb1 = 0 then
set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission
write "A la ligne : " & laligne & " dans liste = " & nb1 & " fichier trouvé. " & return to lelog starting at eof
close access lelog
set drapeau to 1
end if
set liste to liste1
if drapeau = 0 then
repeat with i from 1 to nb1
set lechemin to text item i of liste
set lechemin to lechemin as string
set resultat to resultat as string
set a to (resultat & materiel)
set b to (POSIX file lechemin)
tell application "Finder"
set b to b as alias
set lenom to name of b
--enlever extension
set nomcourt to text 1 thru ((offset of "." in lenom) - 1) of lenom
end tell
tell application "Finder"
if not (exists a) then
make new folder at resultat with properties {name:materiel}
end if
end tell
set a to quoted form of POSIX path of a
set lechemin to quoted form of POSIX path of lechemin
tell application "Finder"
set arenommer to newnom
if (count character of nomcourt) > (count character of lefichier) then
set arenommer to arenommer & "_valide"
end if
set testnom to resultat & materiel & ":" & nomcourt & arenommer & ".pdf"
if (exists testnom) then
set arenommer to arenommer & "_doublon" ---- ajout de double --
end if
end tell
do shell script "cp " & lechemin & " " & a
set anciennom to resultat & materiel & ":" & lenom
set anciennom to quoted form of POSIX path of anciennom
set nouveaunom to resultat & materiel & ":" & nomcourt & arenommer & ".pdf"
set nouveaunom to quoted form of POSIX path of nouveaunom
set commande to "mv " & anciennom & " " & nouveaunom
do shell script commande
set arenommer to ""
end repeat
end if
set drapeau to 0
set laligne to laligne + 1
end repeat
tell application "Finder"
do shell script "rm " & bureau & "liste.txt"
activate
display dialog "termine"
end tell
set resultat to choose folder with prompt "Sélectionner le dossier pour les resultats"
set pdf1 to choose folder with prompt "Sélectionner le premier fichier pour la recherche"
set pdf1 to pdf1 as string
set pdf1 to quoted form of POSIX path of pdf1 as string
set pdf2 to choose folder with prompt "Sélectionner le deuxième dossier pour la recherche"
set pdf2 to pdf2 as string
set pdf2 to quoted form of POSIX path of pdf2 as string
set bureau to POSIX path of (path to desktop folder as text)
set commande to "find " & pdf1 & " -maxdepth 1 -name '*.pdf' > " & bureau & "liste.txt"
do shell script commande
set commande to "find " & pdf2 & " -maxdepth 1 -name '*.pdf' > " & bureau & "liste1.txt"
do shell script commande
set commande to "cat " & bureau & "liste1.txt >> " & bureau & "liste.txt"
do shell script commande
do shell script "rm " & bureau & "liste1.txt"
set laligne to 2
set drapeau to 0
repeat
set liste1 to ""
set nb1 to 0
tell application "Microsoft Excel"
activate
set lefichier to value of range ("a" & laligne)
set lefichier to my entexte(lefichier)
set materiel to value of range ("b" & laligne)
set largeur to value of range ("d" & laligne)
set largeur to my entexte(largeur)
set hauteur to value of range ("e" & laligne)
set hauteur to my entexte(hauteur)
set recto to value of range ("i" & laligne)
set QT to value of range ("m" & laligne)
set QT to my entexte(QT)
end tell
if lefichier is "" then
exit repeat
end if
set newnom to "_" & materiel & "_" & largeur & "_" & hauteur & "_" & recto & "_" & QT & "ex"
--Cherche le fichier
set commande to "grep " & lefichier & " " & bureau & "liste.txt"
try
set liste1 to do shell script commande
on error
set liste1 to ""
end try
set AppleScript's text item delimiters to {return}
set nb1 to count text item of liste1
if nb1 = 0 then
set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission
write "A la ligne : " & laligne & " dans liste = " & nb1 & " fichier trouvé. " & return to lelog starting at eof
close access lelog
set drapeau to 1
end if
set liste to liste1
if drapeau = 0 then
repeat with i from 1 to nb1
set lechemin to text item i of liste
set lechemin to lechemin as string
set resultat to resultat as string
set a to (resultat & materiel)
set b to (POSIX file lechemin)
tell application "Finder"
set b to b as alias
set lenom to name of b
--enlever extension
set nomcourt to text 1 thru ((offset of "." in lenom) - 1) of lenom
end tell
tell application "Finder"
if not (exists a) then
make new folder at resultat with properties {name:materiel}
end if
end tell
set a to quoted form of POSIX path of a
set lechemin to quoted form of POSIX path of lechemin
tell application "Finder"
set arenommer to newnom
if (count character of nomcourt) > (count character of lefichier) then
set arenommer to arenommer & "_valide"
end if
set testnom to resultat & materiel & ":" & nomcourt & arenommer & ".pdf"
if (exists testnom) then
set arenommer to arenommer & "_doublon" ---- ajout de double --
end if
end tell
do shell script "cp " & lechemin & " " & a
set anciennom to resultat & materiel & ":" & lenom
set anciennom to quoted form of POSIX path of anciennom
set nouveaunom to resultat & materiel & ":" & nomcourt & arenommer & ".pdf"
set nouveaunom to quoted form of POSIX path of nouveaunom
set commande to "mv " & anciennom & " " & nouveaunom
do shell script commande
set arenommer to ""
end repeat
end if
set drapeau to 0
set laligne to laligne + 1
end repeat
tell application "Finder"
do shell script "rm " & bureau & "liste.txt"
activate
display dialog "termine"
end tell
on entexte(a)
set AppleScript's text item delimiters to {"E"}
try
set ccc to a
set a to a as text
set b to text item 2 of a
set cc to text item 1 of a
set AppleScript's text item delimiters to {""}
set ccc to (item 1 of cc) & text 3 thru -1 of cc
end try
set AppleScript's text item delimiters to {""}
set lefichier to ccc
end entexte
set resultat to choose folder with prompt "Sélectionner le dossier pour les resultats"
set pdf1 to choose folder with prompt "Sélectionner le premier fichier pour la recherche"
set pdf1 to pdf1 as string
set pdf1 to quoted form of POSIX path of pdf1 as string
set pdf2 to choose folder with prompt "Sélectionner le deuxième dossier pour la recherche"
set pdf2 to pdf2 as string
set pdf2 to quoted form of POSIX path of pdf2 as string
set bureau to POSIX path of (path to desktop folder as text)
set commande to "find " & pdf1 & " -maxdepth 1 -name '*.pdf' > " & bureau & "liste.txt"
do shell script commande
set commande to "find " & pdf2 & " -maxdepth 1 -name '*.pdf' > " & bureau & "liste1.txt"
do shell script commande
set commande to "cat " & bureau & "liste1.txt >> " & bureau & "liste.txt"
do shell script commande
do shell script "rm " & bureau & "liste1.txt"
set laligne to 2
set drapeau to 0
repeat
set liste1 to ""
set nb1 to 0
tell application "Microsoft Excel"
activate
set lefichier to value of range ("a" & laligne)
set lefichier to my entexte(lefichier) as string
set materiel to value of range ("b" & laligne)
set largeur to value of range ("d" & laligne)
set largeur to my entexte(largeur)
set hauteur to value of range ("e" & laligne)
set hauteur to my entexte(hauteur)
set recto to value of range ("i" & laligne)
set QT to value of range ("m" & laligne)
set QT to my entexte(QT)
end tell
if lefichier is "" or lefichier is "0" then
exit repeat
end if
set newnom to "_" & materiel & "_" & largeur & "_" & hauteur & "_" & recto --& "_" --& QT & "ex"
--Cherche le fichier
set commande to "grep " & lefichier & " " & bureau & "liste.txt"
try
set liste1 to do shell script commande
on error
set liste1 to ""
end try
set AppleScript's text item delimiters to {return}
set nb1 to count text item of liste1
if nb1 = 0 then
set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission
write "A la ligne : " & laligne & " dans liste = " & nb1 & " fichier trouvé. " & return to lelog starting at eof
close access lelog
set drapeau to 1
end if
set liste to liste1
if drapeau = 0 then
repeat with i from 1 to nb1
set lechemin to text item i of liste
set lechemin to lechemin as string
set resultat to resultat as string
set a to (resultat & materiel)
set b to (POSIX file lechemin)
tell application "Finder"
set b to b as alias
set lenom to name of b
--enlever extension
set nomcourt to text 1 thru ((offset of "." in lenom) - 1) of lenom
end tell
tell application "Finder"
if not (exists a) then
make new folder at resultat with properties {name:materiel}
end if
end tell
set a to quoted form of POSIX path of a
set lechemin to quoted form of POSIX path of lechemin
tell application "Finder"
set arenommer to newnom
--display dialog "ligne " & laligne & " " & lefichier
set orig to lefichier as string
set nb to count character of orig
if (count character of nomcourt) > nb then
set testnom to resultat & materiel & ":" & nomcourt & arenommer & "_valide" & "_" & QT & "ex" & ".pdf"
if (exists testnom) then
set arenommer to arenommer & "_valide" & "_" & QT & "ex" & "_doublon"
else
set arenommer to arenommer & "_valide" & "_" & QT & "ex"
end if
else
set testnom to resultat & materiel & ":" & nomcourt & arenommer & "_" & QT & "ex" & ".pdf"
if (exists testnom) then
set arenommer to arenommer & "_" & QT & "ex" & "_doublon" ---- ajout de double --
else
set arenommer to arenommer & "_" & QT & "ex"
end if
end if
end tell
do shell script "cp " & lechemin & " " & a
set anciennom to resultat & materiel & ":" & lenom
set anciennom to quoted form of POSIX path of anciennom
set nouveaunom to resultat & materiel & ":" & nomcourt & arenommer & ".pdf"
set nouveaunom to quoted form of POSIX path of nouveaunom
set commande to "mv " & anciennom & " " & nouveaunom
do shell script commande
set arenommer to ""
end repeat
end if
set drapeau to 0
set laligne to laligne + 1
end repeat
tell application "Finder"
do shell script "rm " & bureau & "liste.txt"
activate
display dialog "termine"
end tell
on entexte(a)
try
set a to round of a rounding toward zero
end try
set AppleScript's text item delimiters to {"E"}
try
set ccc to a
set a to a as text
set b to text item 2 of a
set cc to text item 1 of a
set AppleScript's text item delimiters to {""}
set ccc to (item 1 of cc) & text 3 thru -1 of cc
end try
set AppleScript's text item delimiters to {""}
set lefichier to ccc
end entexte