set pdf1 to choose folder with prompt "Sélectionner le dossier pour la recherche"
set pdf1 to pdf1 as string
set pdf1 to quoted form of POSIX path of pdf1 as string
set bureau to POSIX path of (path to desktop folder as text)
set laligne to 2
set drapeau to 0
repeat
tell application "Microsoft Excel"
activate
set lefichier to value of range ("a" & laligne)
set lefichier to my entexte(lefichier) as string
end tell
if lefichier is "" or lefichier is "0" then
exit repeat
end if
set commande to "find " & pdf1 & " -maxdepth 1 -name " & lefichier & "*.pdf"
set lechemin to do shell script commande
set AppleScript's text item delimiters to {return}
set nb to count text item of lechemin
if nb = 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 & " fichier trouvé = " & nb & return to lelog starting at eof
close access lelog
set drapeau to 1
end if
if drapeau = 0 then
if nb > 1 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 & " fichier trouvé = " & nb & return to lelog starting at eof
close access lelog
set drapeau to 1
end if
set lechemin to text item 1 of lechemin
set lecheminmac to (POSIX file lechemin)
tell application "Finder"
set b to lecheminmac 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 "Microsoft Excel"
activate
set value of range ("S" & laligne) to nomcourt
end tell
end if
set drapeau to 0
set laligne to laligne + 1
end repeat
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
set resultat to choose folder with prompt "Sélectionner le dossier pour les resultats"
set ledossier to choose folder with prompt "Sélectionner le dossier pour la recherche des PDF"
set pdf1 to ledossier as string
set pdf1 to quoted form of POSIX path of pdf1 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 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 ("L" & laligne)
set lefichier to my entexte(lefichier) as string
set colm to value of range ("m" & laligne)
set colm to my entexte(colm)
set coln to value of range ("n" & laligne)
set coln to my entexte(coln)
set colk to value of range ("k" & laligne)
set colk to my entexte(colk)
end tell
if lefichier is "" or lefichier is "0" then
exit repeat
end if
set newnom to lefichier & "_" & colm & "_" & coln & "_" & colk & "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 POSIX path of resultat as string
set newnom to resultat & newnom & ".pdf"
set newnom to quoted form of POSIX path of newnom
set anciennom to quoted form of POSIX path of liste
set commande to "cp " & anciennom & " " & newnom
do shell script commande
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
set resultat to choose folder with prompt "Sélectionner le dossier pour les resultats"
set ledossier to choose folder with prompt "Sélectionner le dossier pour la recherche des PDF"
set pdf1 to ledossier as string
set pdf1 to quoted form of POSIX path of pdf1 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 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 ("L" & laligne)
set lefichier to my entexte(lefichier) as string
set colj to value of range ("j" & laligne)
set colj to my entexte(colj)
set coli to value of range ("i" & laligne)
set coli to my entexte(coli)
set colm to value of range ("m" & laligne)
set colm to my entexte(colm)
set coln to value of range ("n" & laligne)
set coln to my entexte(coln)
set colk to value of range ("k" & laligne)
set colk to my entexte(colk)
end tell
if lefichier is "" or lefichier is "0" then
exit repeat
end if
set newnom to lefichier & "_" & colj & "_" & coli & "_" & colm & "_" & coln & "_" & colk & "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 POSIX path of resultat as string
set newnom to resultat & newnom & ".pdf"
set newnom to quoted form of POSIX path of newnom
set anciennom to quoted form of POSIX path of liste
set commande to "cp " & anciennom & " " & newnom
do shell script commande
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
set resultat to choose folder with prompt "Sélectionner le dossier pour les resultats"
set ledossier to choose folder with prompt "Sélectionner le dossier pour la recherche des PDF"
set pdf1 to ledossier as string
set pdf1 to quoted form of POSIX path of pdf1 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 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 ("L" & laligne)
set lefichier to my entexte(lefichier) as string
set colj to value of range ("j" & laligne)
set colj to my entexte(colj)
set coli to value of range ("i" & laligne)
set coli to my entexte(coli)
set colm to value of range ("m" & laligne)
set colm to my entexte(colm)
set coln to value of range ("n" & laligne)
set coln to my entexte(coln)
set colk to value of range ("k" & laligne)
set colk to my entexte(colk)
end tell
if lefichier is "" or lefichier is "0" then
exit repeat
end if
set newnom to lefichier & "_" & colj & "_" & coli & "_" & colm & "_" & coln & "_" & colk & "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 pournom to POSIX file lechemin as alias
tell application "Finder"
set lenom to name of pournom
end tell
set resultat to resultat as string
set newnom to newnom & ".pdf"
set a to POSIX file liste
tell application "Finder"
duplicate a to resultat
set newfile to (resultat & lenom) as alias
set name of newfile to newnom
end tell
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
set resultat to choose folder with prompt "Sélectionner le dossier pour les resultats"
set ledossier to choose folder with prompt "Sélectionner le dossier pour la recherche des PDF"
set pdf1 to ledossier as string
set pdf1 to quoted form of POSIX path of pdf1 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 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 ("L" & laligne)
try
set test to lefichier + 0
set lefichier to my entexte(lefichier) as string
end try
set colj to value of range ("j" & laligne)
try
set test to colj + 0
set colj to my entexte(colj)
end try
set coli to value of range ("i" & laligne)
try
set test to coli + 0
set coli to my entexte(coli)
end try
set colm to value of range ("m" & laligne)
try
set test to colm + 0
set colm to my entexte(colm)
end try
set coln to value of range ("n" & laligne)
try
set test to coln + 0
set coln to my entexte(coln)
end try
set colk to value of range ("k" & laligne)
try
set test to colk + 0
set colk to my entexte(colk)
end try
end tell
if lefichier is "" or lefichier is "0" then
exit repeat
end if
set newnom to lefichier & "_" & colj & "_" & coli & "_" & colm & "_" & coln & "_" & colk & "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 pournom to POSIX file lechemin as alias
tell application "Finder"
set lenom to name of pournom
end tell
set resultat to resultat as string
set newnom to newnom & ".pdf"
set a to POSIX file liste
tell application "Finder"
duplicate a to resultat
set newfile to (resultat & lenom) as alias
set name of newfile to newnom
end tell
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