Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

erreur dans un Split de csv

4 réponses
Avatar
---DGI972---
Bonjour,

J'essaye de fabriquer un csv a partir d'un autre csv qui contiendrait
le nom de l'image tif a renommer, un point virgule et le nouveau nom
tif de cette image a renommer.
Je voudrais par la suite (on verra après) lancer un renommage des
toutes ces images.
voici la structure du csv d'entrée:

01490000,MR
TOTO,900,000,,0056814.tif,290,20001024,0056815.tif,290,20001024,0056816.tif,790,,0056817.tif
00770000,MR
TATA,900,000,,0056818.tif,290,20011204,0056819.tif,290,20011204,0056820.tif,790,,0056821.tif
00221000,MR
TITI,900,000,,0056822.tif,290,20070822,0056823.tif,290,20070822,0056824.tif,215,,0056825.tif
00000900,M.
TETE,900,000,,0056843.tif,730,20050318,0056844.tif,790,,0056845.tif,680,,0056846.tif,300,22040107,0056847.tif
49743000,MR
TUTU,900,000,,0056848.tif,300,19980519,0056849.tif,215,,0056850.tif
498,MLLE
TYTY,900,000,,0057066.tif,300,19990313,0057067.tif,795,,0057068.tif,000,,0057069.tif,290,20010625,0057070.tif,790,,0057071.tif,680,,0057072.tif,290,20001123,0057073.tif

J'avais dans l'idée de lire le csv en entrée, de créer un sous
répertoire PDF dans le répertoire de travail et de créer un nouveau
fichier csv.

Voici mon bout de script (sans la fonction chooseFile):

fichCSV = ChooseFile()
Set oFs=CreateObject("Scripting.FileSystemObject")
Set oFileIn=oFs.OpenTextFile(fichCSV)
sCurrentFolder=oFs.GetParentFolderName(fichCSV)
Set objFolder=oFs.createFolder(sCurrentFolder&"\PDF")
Set
oFileOut=oFs.OpenTextFile(sCurrentFolder&"\PDF\"&oFs.GetBaseName(fichCSV)&".csv",2,
True)

While Not oFileIn.AtEndOfStream
arrVars=split (oFileIn.ReadLine, ",")
ENT=arrVars (2)&arrVars (0)
If arrVars (8)<>"" then A=arrVars (8)&";"&ENT&arrVars (6)&arrVars
(7)&".tif"&VbCrLf
If arrVars (11)<>"" then B=arrVars (11)&";"&ENT&arrVars (9)&arrVars
(10)&".tif"&VbCrLf
If arrVars (14)<>"" then C=arrVars (14)&";"&ENT&arrVars (12)&arrVars
(13)&".tif"&VbCrLf
If arrVars (17)<>"" then D=arrVars (17)&";"&ENT&arrVars (15)&arrVars
(16)&".tif"&VbCrLf
If arrVars (20)<>"" then E=arrVars (20)&";"&ENT&arrVars (18)&arrVars
(19)&".tif"&VbCrLf
If arrVars (23)<>"" then F=arrVars (23)&";"&ENT&arrVars (21)&arrVars
(22)&".tif"&VbCrLf
If arrVars (26)<>"" then G=arrVars (26)&";"&ENT&arrVars (24)&arrVars
(25)&".tif"&VbCrLf
oFileOut.Write A&B&C&D&E&F&G
Wend
Wscript.echo "Fichier CSV crée pour la création des Pdf"
WScript.Quit

J'ai un beau indice en dehors de la plage:'[number:17]' à la ligne If
arrVars (17)<>"" then D=arrVars (17)&";"&ENT&arrVars (15)&arrVars
(16)&".tif"&VbCrLf.

le sous répertoire est créé et le csv est vide.

Merci

4 réponses

Avatar
Lotre
Bonjour,

Euh ...

Pour de telles manip, il vaut mieux que le nombre des champs soit
fixe... Or, avec ce que tu fournis comme "structure du csv" cela n'est
visiblement pas le cas .

Le script cherche jusqu'au n° 26 ( soit le 27-ième champs ), mais les
lignes de TUTU et de TYTY ont des longueurs très différentes ... Si
c'est normal, il va falloir après le split, récupérer le dernier
indice N et modifier la série des affectations ...

Il sera alors plus simple de faire une seconde boucle :
' ======================================= ' ( ... début)
While Not oFileIn.AtEndOfStream
arrVars=split (oFileIn.ReadLine, ",")
N = ubound(arrVars)

Sortie=""
For Rang= 8 to N Step 3
' si j'ai bien compris ce que tu désires faire ... !
" °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

If arrVars (Rang)<>"" then
Sortie = Sortie & arrVars (Rang) & ";" & ENT _
& arrVars (Rang - 2) & arrVars(Rang - 1) _
&".tif" & VbCrLf
End If
Next
oFileOut.Write Sortie
Wend
' ( ... fin)
' ============================================= ---DGI972--- wrote:
Bonjour,

J'essaye de fabriquer un csv a partir d'un autre csv qui
contiendrait
le nom de l'image tif a renommer, un point virgule et le nouveau nom
tif de cette image a renommer.
Je voudrais par la suite (on verra après) lancer un renommage des
toutes ces images.
voici la structure du csv d'entrée:

01490000,MR
TOTO,900,000,,0056814.tif,290,20001024,0056815.tif,290,20001024,0056816.tif,790,,0056817.tif
00770000,MR
TATA,900,000,,0056818.tif,290,20011204,0056819.tif,290,20011204,0056820.tif,790,,0056821.tif
00221000,MR
TITI,900,000,,0056822.tif,290,20070822,0056823.tif,290,20070822,0056824.tif,215,,0056825.tif
00000900,M.
TETE,900,000,,0056843.tif,730,20050318,0056844.tif,790,,0056845.tif,680,,0056846.tif,300,22040107,0056847.tif
49743000,MR
TUTU,900,000,,0056848.tif,300,19980519,0056849.tif,215,,0056850.tif
498,MLLE
TYTY,900,000,,0057066.tif,300,19990313,0057067.tif,795,,0057068.tif,000,,0057069.tif,290,20010625,0057070.tif,790,,0057071.tif,680,,0057072.tif,290,20001123,0057073.tif

J'avais dans l'idée de lire le csv en entrée, de créer un sous
répertoire PDF dans le répertoire de travail et de créer un nouveau
fichier csv.

Voici mon bout de script (sans la fonction chooseFile):

fichCSV = ChooseFile()
Set oFs=CreateObject("Scripting.FileSystemObject")
Set oFileIn=oFs.OpenTextFile(fichCSV)
sCurrentFolder=oFs.GetParentFolderName(fichCSV)
Set objFolder=oFs.createFolder(sCurrentFolder&"PDF")
Set
oFileOut=oFs.OpenTextFile(sCurrentFolder&"PDF"&oFs.GetBaseName(fichCSV)&".csv",2,
True)

While Not oFileIn.AtEndOfStream
arrVars=split (oFileIn.ReadLine, ",")
ENT=arrVars (2)&arrVars (0)
If arrVars (8)<>"" then A=arrVars (8)&";"&ENT&arrVars (6)&arrVars
(7)&".tif"&VbCrLf
If arrVars (11)<>"" then B=arrVars (11)&";"&ENT&arrVars (9)&arrVars
(10)&".tif"&VbCrLf
If arrVars (14)<>"" then C=arrVars (14)&";"&ENT&arrVars (12)&arrVars
(13)&".tif"&VbCrLf
If arrVars (17)<>"" then D=arrVars (17)&";"&ENT&arrVars (15)&arrVars
(16)&".tif"&VbCrLf
If arrVars (20)<>"" then E=arrVars (20)&";"&ENT&arrVars (18)&arrVars
(19)&".tif"&VbCrLf
If arrVars (23)<>"" then F=arrVars (23)&";"&ENT&arrVars (21)&arrVars
(22)&".tif"&VbCrLf
If arrVars (26)<>"" then G=arrVars (26)&";"&ENT&arrVars (24)&arrVars
(25)&".tif"&VbCrLf
oFileOut.Write A&B&C&D&E&F&G
Wend
Wscript.echo "Fichier CSV crée pour la création des Pdf"
WScript.Quit

J'ai un beau indice en dehors de la plage:'[number:17]' à la ligne
If
arrVars (17)<>"" then D=arrVars (17)&";"&ENT&arrVars (15)&arrVars
(16)&".tif"&VbCrLf.

le sous répertoire est créé et le csv est vide.

Merci


Avatar
---DGI972---
Lotre a écrit :
Bonjour,

Euh ...

Pour de telles manip, il vaut mieux que le nombre des champs soit fixe... Or,
avec ce que tu fournis comme "structure du csv" cela n'est visiblement pas le
cas .

Le script cherche jusqu'au n° 26 ( soit le 27-ième champs ), mais les lignes
de TUTU et de TYTY ont des longueurs très différentes ... Si c'est normal, il
va falloir après le split, récupérer le dernier indice N et modifier la série
des affectations ...

Il sera alors plus simple de faire une seconde boucle :
' ======================================= > ' ( ... début)
While Not oFileIn.AtEndOfStream
arrVars=split (oFileIn.ReadLine, ",")
N = ubound(arrVars)

Sortie=""
For Rang= 8 to N Step 3
' si j'ai bien compris ce que tu désires faire ... !
" °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

If arrVars (Rang)<>"" then
Sortie = Sortie & arrVars (Rang) & ";" & ENT _
& arrVars (Rang - 2) & arrVars(Rang - 1) _
&".tif" & VbCrLf
End If
Next
oFileOut.Write Sortie
Wend
' ( ... fin)
' ============================================= > ---DGI972--- wrote:
Bonjour,

J'essaye de fabriquer un csv a partir d'un autre csv qui contiendrait
le nom de l'image tif a renommer, un point virgule et le nouveau nom
tif de cette image a renommer.
Je voudrais par la suite (on verra après) lancer un renommage des
toutes ces images.
voici la structure du csv d'entrée:

01490000,MR
TOTO,900,000,,0056814.tif,290,20001024,0056815.tif,290,20001024,0056816.tif,790,,0056817.tif
00770000,MR
TATA,900,000,,0056818.tif,290,20011204,0056819.tif,290,20011204,0056820.tif,790,,0056821.tif
00221000,MR
TITI,900,000,,0056822.tif,290,20070822,0056823.tif,290,20070822,0056824.tif,215,,0056825.tif
00000900,M.
TETE,900,000,,0056843.tif,730,20050318,0056844.tif,790,,0056845.tif,680,,0056846.tif,300,22040107,0056847.tif
49743000,MR
TUTU,900,000,,0056848.tif,300,19980519,0056849.tif,215,,0056850.tif
498,MLLE
TYTY,900,000,,0057066.tif,300,19990313,0057067.tif,795,,0057068.tif,000,,0057069.tif,290,20010625,0057070.tif,790,,0057071.tif,680,,0057072.tif,290,20001123,0057073.tif

J'avais dans l'idée de lire le csv en entrée, de créer un sous
répertoire PDF dans le répertoire de travail et de créer un nouveau
fichier csv.

Voici mon bout de script (sans la fonction chooseFile):

fichCSV = ChooseFile()
Set oFs=CreateObject("Scripting.FileSystemObject")
Set oFileIn=oFs.OpenTextFile(fichCSV)
sCurrentFolder=oFs.GetParentFolderName(fichCSV)
Set objFolder=oFs.createFolder(sCurrentFolder&"PDF")
Set
oFileOut=oFs.OpenTextFile(sCurrentFolder&"PDF"&oFs.GetBaseName(fichCSV)&".csv",2,
True)

While Not oFileIn.AtEndOfStream
arrVars=split (oFileIn.ReadLine, ",")
ENT=arrVars (2)&arrVars (0)
If arrVars (8)<>"" then A=arrVars (8)&";"&ENT&arrVars (6)&arrVars
(7)&".tif"&VbCrLf
If arrVars (11)<>"" then B=arrVars (11)&";"&ENT&arrVars (9)&arrVars
(10)&".tif"&VbCrLf
If arrVars (14)<>"" then C=arrVars (14)&";"&ENT&arrVars (12)&arrVars
(13)&".tif"&VbCrLf
If arrVars (17)<>"" then D=arrVars (17)&";"&ENT&arrVars (15)&arrVars
(16)&".tif"&VbCrLf
If arrVars (20)<>"" then E=arrVars (20)&";"&ENT&arrVars (18)&arrVars
(19)&".tif"&VbCrLf
If arrVars (23)<>"" then F=arrVars (23)&";"&ENT&arrVars (21)&arrVars
(22)&".tif"&VbCrLf
If arrVars (26)<>"" then G=arrVars (26)&";"&ENT&arrVars (24)&arrVars
(25)&".tif"&VbCrLf
oFileOut.Write A&B&C&D&E&F&G
Wend
Wscript.echo "Fichier CSV crée pour la création des Pdf"
WScript.Quit

J'ai un beau indice en dehors de la plage:'[number:17]' à la ligne If
arrVars (17)<>"" then D=arrVars (17)&";"&ENT&arrVars (15)&arrVars
(16)&".tif"&VbCrLf.

le sous répertoire est créé et le csv est vide.

Merci





Le fichier de sortie est exactement comme celui que j'attendais.
Bien vu que le coup du step 3 (j'avais même pas fait attention).
Merci je continue, il me reste le renommage proprement dit des fichiers
et je m'aperçois que j'ai des tif en double qu'il faudra concaténer en
multi-Tif.
Merci encore.
Avatar
Lotre
Bonjour,


---DGI972--- wrote:
(...)

Le fichier de sortie est exactement comme celui que j'attendais.



j'en suis ravi !

Bien vu que le coup du step 3 (j'avais même pas fait attention).



... et oui ... celui qui force sur les pédales
ne regarde pas forcément la route ... ;o)

Merci je continue, il me reste (...)
Merci encore.



pour la suite ... on attend ;o)

HB
Avatar
---DGI972---
Après mûre réflexion, Lotre a écrit :
Bonjour,


---DGI972--- wrote:
(...)

Le fichier de sortie est exactement comme celui que j'attendais.



j'en suis ravi !

Bien vu que le coup du step 3 (j'avais même pas fait attention).



... et oui ... celui qui force sur les pédales
ne regarde pas forcément la route ... ;o)

Merci je continue, il me reste (...)
Merci encore.



pour la suite ... on attend ;o)

HB



Bonjour,

voila la suite:

Set
oFileIn=oFs.OpenTextFile(sCurrentFolder&"PDF"&oFs.GetBaseName(fichCSV)&".csv")
Const OverwriteExisting = True
While Not oFileIn.AtEndOfStream
arrVars=split (oFileIn.ReadLine, ";")
oFs.CopyFile sCurrentFolder&""&arrVars
(0),sCurrentFolder&"PDF"&arrVars (1),OverwriteExisting
Wend

CHEMIN1=sCurrentFolder&""
CHEMIN2=sCurrentFolder&"PDF"
STRCMD="%COMSPEC% /c c:progtiff2pdf.cmd " 'conversion tiff 2 pdf en
ligne de commande
CreateObject("WScript.Shell").run STRCMD & Chr(34) & CHEMIN1 & Chr(34)
& Chr(34) & CHEMIN2 & Chr(34), 0, True
Wscript.echo "Le renommage et la création des Pdf a bien été traitée"

Cela me créé bien mes fichiers avec le bon nom mais lorsque le fichier
de destination existe déjà il est écrasé par la dernière copie de
fichier (et c'est normal). Est ce que l'on peut gérer l'erreur
OverwriteExisting pour déclencher une concaténation de fichiers tiff ?

J'ai trouvé un exe tiffcp.exe qui concatène des fichiers tif voici la
commande par ex:
C:Progtiffcp 0056815.tif 0056816.tif 90012345629001012009.tif

Voici un exemple de fichier crée avec le nom de l'image; le nom nom a
copier dans le sous répertoire PDF. Deux images ont le même nom de
fichier car en fait c'est le recto et verso d'un même numéro de client

0056815.tif;9000149078829020001024.tif
0056816.tif;9000149078829020001024.tif
0056817.tif;90001490788790.tif
0056819.tif;9000077052329020011204.tif
0056820.tif;9000077052329020011204.tif
0056821.tif;90000770523790.tif
0056823.tif;9000022134129020070822.tif
0056824.tif;9000022134129020070822.tif
0056825.tif;90000221341215.tif
0056827.tif;9000005398829020061211.tif
0056828.tif;9000005398829020061211.tif
0056829.tif;90000053988790.tif
0056831.tif;9000183391029019990323.tif
0056832.tif;9000183391029019990323.tif
0056833.tif;90001833910800.tif
0056835.tif;9000131570629020010516.tif
0056836.tif;9000131570629020010516.tif
0056837.tif;90001315706790.tif
0056839.tif;9000000040229020070606.tif
0056840.tif;90000000402790.tif
0056841.tif;90000000402680.tif
0056842.tif;9000000040229019981022.tif
0056844.tif;9000000091073020050318.tif

Voici le bat pour la conversion des fichiers tiff en pdf

-----tiff2pdf.cmd----
@echo off
@setlocal enabledelayedexpansion
@SETLOCAL ENABLEEXTENSIONS
cd
for /f "delims=." %%i in ('dir/b %~1*.tif') DO (
C:CRCAGPROGtiff2pdf -o "%~2%~nI.pdf" "%~1%~nxI"
)
endlocal
-----tiff2pdf.cmd----

merci