Je débute en programmation (très amateur/débutant) et j'ai de la difficulté avec un code en vbs.
J,aimerais faire le lien entre les 2 codes pour récupéré le fichier sélectionné dans le 1er code pour l'utiliser comme source pour le 2e code. Voici les 2 codes en question. Dans le fond, la partie en gras doit être le fichier que j'ai sélectionné préalablement avec le 1er code.
1er code
'-- Hwnd is always 0. Title is browse window caption. RootFolder is optional top folder to show.
'-- Options has several possibilities:
'-- 1 - only allows selection of system folders. (doesn't seem to work.)
'-- 2 - don't show network folders below domain level. (doesn't work on stand-alone system.)
'-- 8 - only allow selection of File System ancestors(??) (on stand-alone system nothing can be selected.)
'-- 16 - adds a text input but only valid entries will be returned; cannot create a folder.
'-- 4096 - only computers can be selected.
'-- 8192 - only a printer can be selected.
'-- 16384 - full browsing, includes files.
'-- This script uses the FolderItems object properties to Get path and
'-- find out what type of item it is.
Dim ShellApp, Ret, s, i
Set ShellApp = CreateObject("Shell.Application")
On Error Resume Next
Set Ret = ShellApp.BrowseForFolder(0, "Choose a file or folder", 16384)
s = Ret.title
If Err.number <> 0 Then
WScript.Quit
End If
s = GetPath(Ret, i)
MsgBox s & " - " & cstr(i) &vbcrlf&vbcrlf&"0-namespace. 1-drive. 2-folder. 3-file." '--show full path and type of item returned. 0-namespace. 1-drive. 2-folder. 3-file.
Set ShellApp = nothing
WScript.Quit
Function GetPath(Fil, iItem)
Dim Pt1, fPar, sn, Obj, sType
On Error Resume Next
sn = Fil.title
MsgBox "sn (File/Folder title): " &sn
Set fPar = Fil.parentfolder
MsgBox "fPar (File/Folder parent Folder): " &fpar
Set Obj = fPar.parsename(sn) '--return item selected as a Shell FolderItem.
MsgBox "Obj (return item selected as a Shell FolderItem): " &obj
'--weed out namespaces and drives. If it's a namespace or drive it can't
'--return a FolderItem so the last Call caused an error and Obj is therefore
'--Not part of the filesystem:
If Obj.isfilesystem = false Then
Pt1 = instr(sn, ":")
If Pt1 = 0 Then
iItem = 0 '--namespace.
getpath = sn
Else
iItem = 1 '--drive.
getpath = mid(sn, (Pt1 - 1), 2) & "\" '--Get letter before : and add "\" If drive.
End If
Set Obj = nothing
exit Function
End If
'--it's a file or folder. find out which and Get path:
sType = Obj.type '--Get object Type as shown in folder Details view.
MsgBox "sType (Get object Type as shown in folder Details view): " &sType '-- Should be able to use: If Obj.IsFolder = True..... but it doesn't work.
If instr(sType, "Bestandsmap") = 0 Then '-TAALGEVOELIG-in detail view a folder will be type "File Folder".
iItem = 3 '--file.
Else
iItem = 2 '--folder.
End If
getpath = Obj.path
Set Obj = Nothing
End Function
2e code
nomfich="C:\Users\......\clients.txt" Set fs = CreateObject("Scripting.FileSystemObject")
Set fich_source = fs.OpenTextFile(nomfich, 1, False)
Set nouv_fich = fs.OpenTextFile("C:\Users\......\clients1.txt", 2, true)
fich_source.readLine
Do While not fich_source.AtEndOfStream
nouv_fich.writeLine fich_source.readLine
Loop
nouv_fich.close
fich_source.close
Set nouv_fich=nothing
Set fich_source=nothing
Set fs=nothing
Tout aide sera grandement apprécié. Mon expérience est très limité et à part vous, je n'ai personne vers qui poser les questions quand j'ai un problème dont je ne trouve pas la réponse sur le web.
A voir également:
Récupérer un fichier pour s'en servir comme source