[DOS] recopier des lignes au format DOS

recopier des lignes au format DOS [DOS] - Shell/Batch - Programmation

Marsh Posté le 12-04-2007 à 09:10:31    

Bonjour,
 
J'ai un fichier texte liste_dossiers.txt contenant des lignes correspondant à des noms de dossiers.
Je souhaite réécrire de fichier texte dans un nouveau liste_dossiers2.txt où chaque ligne du fichier liste_dossiers.txt serait réécrite avec un formatage DOS.
Ainsi, les lignes  
 
échange
écologie
carrière
 
deviendraient
 
‚change
‚cologie
carriŠre
 
Je sais déjà comment récupérer chaque ligne du fichier texte. Ne reste plus qu'à faire en sorte que ça réécrive au format DOS...

Code :
  1. @echo off
  2. for /f "eol=; tokens=1 delims=," %%a in (liste_dossiers.txt) do (
  3. echo   %%a
  4. )
  5. pause


 
Si vous avez des idées, éviemment, je suis preneur  :)  
 
A +

Reply

Marsh Posté le 12-04-2007 à 09:10:31   

Reply

Marsh Posté le 12-04-2007 à 09:24:34    

Je ne sias pas si c'est possible


Message édité par webding le 12-04-2007 à 09:24:44
Reply

Marsh Posté le 12-04-2007 à 12:21:34    

Pas possible en batch Windows, encore moins sous DOS.
 
Le format que tu appelles DOS s'appelle OEM, si tu veux Googliser pour "OEM ANSI converter".

Reply

Marsh Posté le 12-04-2007 à 12:24:33    

Mais on peut faire ca en VBS:
 
oem2ansi fichier1originale fichier2sortie
 

Code :
  1. ' ----------------------------------------------------------
  2. ' Script de Conversion ANSI -> OEM
  3. '
  4. ' Syntaxe:
  5. '   oem2ansi <srce> <dest>
  6. '   <srce> : fichier source (texte ANSI)
  7. '   <dest> : fichier destination (texte OEM)
  8. '
  9. ' JC BELLAMY © 2002
  10. ' ----------------------------------------------------------
  11. Dim ansi
  12. ansi=array( _
  13. "00","01","02","03","04","05","06","07","08","09","0A","0B","0C","0D","0E","0F", _
  14. "10","11","12","13","14","15","16","17","18","19","1A","1B","1C","1D","1E","1F", _
  15. "20","21","22","23","24","25","26","27","28","29","2A","2B","2C","2D","2E","2F", _
  16. "30","31","32","33","34","35","36","37","38","39","3A","3B","3C","3D","3E","3F", _
  17. "40","41","42","43","44","45","46","47","48","49","4A","4B","4C","4D","4E","4F", _
  18. "50","51","52","53","54","55","56","57","58","59","5A","5B","5C","5D","5E","5F", _
  19. "60","61","62","63","64","65","66","67","68","69","6A","6B","6C","6D","6E","6F", _
  20. "70","71","72","73","74","75","76","77","78","79","7A","7B","7C","7D","7E","7F", _
  21. "5F","5F","27","9F","22","2E","C5","CE","5E","25","53","3C","4F","5F","5A","5F", _
  22. "5F","27","27","22","22","07","2D","2D","7E","54","73","3E","6F","5F","7A","59", _
  23. "FF","AD","BD","9C","CF","BE","DD","F5","F9","B8","A6","AE","AA","F0","A9","EE", _
  24. "F8","F1","FD","FC","EF","E6","F4","FA","F7","FB","A7","AF","AC","AB","F3","A8", _
  25. "B7","B5","B6","C7","8E","8F","92","80","D4","90","D2","D3","DE","D6","D7","D8", _
  26. "D1","A5","E3","E0","E2","E5","99","9E","9D","EB","E9","EA","9A","ED","E8","E1", _
  27. "85","A0","83","C6","84","86","91","87","8A","82","88","89","8D","A1","8C","8B", _
  28. "D0","A4","95","A2","93","E4","94","F6","9B","97","A3","96","81","EC","E7","98" )
  29. ForReading = 1
  30. ForWriting = 2
  31. Dim args, fso, fsrce, fdest
  32. Set fso   = WScript.CreateObject("Scripting.FileSystemObject" )
  33. Set args  = Wscript.Arguments
  34. ' Conversion OEM -> ANSI
  35. If args.count<2 Then
  36. strFullName =lcase(WScript.FullName)
  37. i=InStr(1,strFullName,".exe",1)
  38. j=InStrRev(strFullName,"\",i,1)
  39. strCommand=Mid(strFullName,j+1,i-j-1)
  40. if strCommand<>"cscript" then
  41.  Mess=       "Conversion ANSI -> OEM" & VBCRLF
  42.  Mess=Mess & "JCB © 2002" & VBCRLF
  43.  Mess=Mess & "----------------------" & VBCRLF
  44.  Mess=Mess & "Syntaxe : " & VBCRLF
  45.  Mess=Mess & "   ansi2oem <srce> <dest>"  & VBCRLF
  46.  Mess=Mess & "   <srce> : fichier source (texte ANSI)" & VBCRLF
  47.  Mess=Mess & "   <dest> : fichier destination (texte OEM)" & VBCRLF
  48.  Mess=Mess & "NB: pour utiliser les flux standards 'stdin' et 'stdout'," & VBCRLF
  49.  Mess=Mess & "    le moteur de script par défaut doit être cscript.exe" & VBCRLF
  50.  Mess=Mess & "    Cela s'obtient par la commande : " & VBCRLF
  51.  Mess=Mess & "     cscript //H:CScript //S /Nologo" & VBCRLF & VBCRLF
  52.  Mess=Mess & "Si le script récupère en entrée la sortie d'un autre logiciel (piping)," & VBCRLF
  53.  Mess=Mess & "il faut indiquer explicitement 'cscript'" & VBCRLF
  54.  Mess=Mess & "Exemple :" & VBCRLF
  55.  Mess=Mess & "c:\>appliansi.exe | cscript ansi2oem.vbs > test.txt" & VBCRLF & VBCRLF
  56.  wscript.echo Mess
  57.  wscript.quit
  58. else
  59.  Pipe=true
  60.  Set fsrce = WScript.StdIn
  61.  Set fdest = WScript.StdOut
  62.  end if
  63. else
  64. Pipe=false
  65. srce=args(0)
  66. dest=args(1)
  67. If not fso.FileExists(srce) Then
  68.  Mess="Le fichier " & srce & " n'existe pas"
  69.  wscript.echo Mess
  70.  wscript.quit
  71.  End If
  72. Set fsrce=fso.OpenTextFile(srce, ForReading)
  73. Set fdest=fso.OpenTextFile(dest, ForWriting,true)
  74. End If
  75. While not fsrce.AtEndOfStream
  76. oldline=fsrce.ReadLine
  77. newline=""
  78. For i = 1 To len(oldline)
  79.  oldc=asc(mid(oldline,i,1))
  80.  newc=ansi(oldc)
  81.  newline=newline & chr(hextobyte(newc))
  82.  Next
  83. fdest.WriteLine newline
  84. Wend
  85. fdest.close
  86. fsrce.close
  87. 'If not pipe Then wscript.echo "Conversion terminée"
  88. Wscript.quit
  89. ' Utilitaires de conversion hexadécimale
  90. ' -------------------------------------
  91. Function hextobyte(s)
  92. c1=Left(s,1)
  93. c2=Right(s,1)
  94. hextobyte=hextobin(c1)*16+hextobin(c2)
  95. End Function
  96. ' -------------------------------------
  97. Function hextobin(c)
  98. Select Case c
  99. Case "0","1","2","3","4","5","6","7","8","9"
  100.  hextobin=asc(c)-asc("0" )   
  101. Case else
  102.  hextobin=asc(c)-asc("A" )+10
  103. End Select
  104. End Function
  105. ' -------------------------------------


Message édité par webding le 12-04-2007 à 12:25:49
Reply

Marsh Posté le 12-04-2007 à 14:44:02    

merci beaucoup pour vos réponses. C'est moins simple que je ne pensais :). Je vais essayer de me pencher sur le VBS. Je ne l'ai jamais fait...
 
A bientôt,

Reply

Marsh Posté le 12-04-2007 à 15:07:54    

Ce script VBS tu peut l'utiliser en ligne de commande, tu nomme le script oem2ansi et tu l'utilise commae ceci:

Code :
  1. oem2ansi fichier1originale fichier2sortie


 
Fait un essay et dit moi si sa marche


Message édité par webding le 12-04-2007 à 15:09:00
Reply

Marsh Posté le 12-04-2007 à 16:37:34    

je n'ai jamais fait de VBS. Aussi, je ne sais donc pas comment créer un script VBS. Je vais regarder ça. Je te préviendrai si ça marche!

Reply

Marsh Posté le 12-04-2007 à 16:39:24    

Ben tu copie le code que je t'est donné dans un fichier.txt puis tu l'enregistre avec comme non oem2ansi et commen extension .vbs tout simplement


Message édité par webding le 12-04-2007 à 16:40:14
Reply

Marsh Posté le 12-04-2007 à 17:47:25    

ah ok :) merci!

Reply

Marsh Posté le 12-04-2007 à 17:49:08    

alor ta essayer ?

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed