I would like to create a command that read a "*.*" argument and then
apply a command for each file... But this jokers are note evaluated and a
only a string like any other.
So can anyone tell me how to really evaluate the *.* in JScript
please ?
Another problem is that when I apply to commands using the shell.run()
or shell.exec() methods, it seems to launch all process simultanously
and I would like that each process wait the end of the previous one ?
Any tip ?
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Pif
Oups... j'avais pas vu que c'était frenchy ! désolé...
Bon, en francais, j'ai deux problème...
Je veux passer en argument *.* ou une liste de fichiers, et ensuite appliquer mes commandes à chacun des fichiers. Comment faire, il ne considère cela que comme un argument chaine de caractère et ne le converti jamais en liste, ne l'évalue jamais...
Sinon, ensuite, quand je lance mes commandes, elle semblent être lancées en parallèe.. je voudrais que chaque process attende la fin des précédents... j'ai essayé un shell.exec() ou shell.run()... dans aucun des cas ca ne marche !?
Merci !
des suggestions ?
Oups... j'avais pas vu que c'était frenchy ! désolé...
Bon, en francais, j'ai deux problème...
Je veux passer en argument *.* ou une liste de fichiers, et ensuite
appliquer mes commandes à chacun des fichiers. Comment faire, il ne considère
cela que comme un argument chaine de caractère et ne le converti jamais en
liste, ne l'évalue jamais...
Sinon, ensuite, quand je lance mes commandes, elle semblent être lancées en
parallèe.. je voudrais que chaque process attende la fin des précédents...
j'ai essayé un shell.exec() ou shell.run()... dans aucun des cas ca ne marche
!?
Oups... j'avais pas vu que c'était frenchy ! désolé...
Bon, en francais, j'ai deux problème...
Je veux passer en argument *.* ou une liste de fichiers, et ensuite appliquer mes commandes à chacun des fichiers. Comment faire, il ne considère cela que comme un argument chaine de caractère et ne le converti jamais en liste, ne l'évalue jamais...
Sinon, ensuite, quand je lance mes commandes, elle semblent être lancées en parallèe.. je voudrais que chaque process attende la fin des précédents... j'ai essayé un shell.exec() ou shell.run()... dans aucun des cas ca ne marche !?
en effet, c'est pas du JS, mais je savais pas comment faire un batch, et je m'étais redirigé vers le JS parceque WHS semblait remplacer les batch...
Bon, ben du coup... je vais mémoriser la solution au moins...
Vous connaissez des bons tutorie, bouquin ou autre ou on peut avoir une description exacte de la liste des fonctionnalités du batch ou WHS/JS et pas a chaque fois simple un "comment faire une boucle"... ? Vous avez appris ou ce genre d'astuce...
Merci !
"MC" wrote:
Bonjour !
Bonjour, peux tu développer un peu ? Désolé, je n'avais pas vu le mot "jscript". Ma proposition était en
batch. Comme elle est facile je la met quand même :
echo off for /F "usebackq" %%i in (`dir C:*.jpg C:*.jpeg C:*.reg /B`) do call :TRAITEMENT %%i goto :EOF
en effet, c'est pas du JS, mais je savais pas comment faire un batch, et je
m'étais redirigé vers le JS parceque WHS semblait remplacer les batch...
Bon, ben du coup... je vais mémoriser la solution au moins...
Vous connaissez des bons tutorie, bouquin ou autre ou on peut avoir une
description exacte de la liste des fonctionnalités du batch ou WHS/JS et pas
a chaque fois simple un "comment faire une boucle"... ? Vous avez appris ou
ce genre d'astuce...
Merci !
"MC" wrote:
Bonjour !
Bonjour, peux tu développer un peu ?
Désolé, je n'avais pas vu le mot "jscript". Ma proposition était en
batch.
Comme elle est facile je la met quand même :
echo off
for /F "usebackq" %%i in (`dir C:*.jpg C:*.jpeg C:*.reg /B`) do call
:TRAITEMENT %%i
goto :EOF
en effet, c'est pas du JS, mais je savais pas comment faire un batch, et je m'étais redirigé vers le JS parceque WHS semblait remplacer les batch...
Bon, ben du coup... je vais mémoriser la solution au moins...
Vous connaissez des bons tutorie, bouquin ou autre ou on peut avoir une description exacte de la liste des fonctionnalités du batch ou WHS/JS et pas a chaque fois simple un "comment faire une boucle"... ? Vous avez appris ou ce genre d'astuce...
Merci !
"MC" wrote:
Bonjour !
Bonjour, peux tu développer un peu ? Désolé, je n'avais pas vu le mot "jscript". Ma proposition était en
batch. Comme elle est facile je la met quand même :
echo off for /F "usebackq" %%i in (`dir C:*.jpg C:*.jpeg C:*.reg /B`) do call :TRAITEMENT %%i goto :EOF
Il y a plusieurs explications possibles : - c'est inscrit dans mes gênes - dans une invite de commande, j'ai tapé, par hasard, FOR /? - il s'agit d'une technologie extra-terrestre ; je ne peux donc dévoiler mes sources - dans "Démarrer" + "Aide", j'ai cherché "ligne de commande"
-- @-salutations
Michel Claveau
Bonsoir !
Vous avez appris où ce genre d'astuce ?
Il y a plusieurs explications possibles :
- c'est inscrit dans mes gênes
- dans une invite de commande, j'ai tapé, par hasard, FOR /?
- il s'agit d'une technologie extra-terrestre ; je ne peux donc
dévoiler mes sources
- dans "Démarrer" + "Aide", j'ai cherché "ligne de commande"
Il y a plusieurs explications possibles : - c'est inscrit dans mes gênes - dans une invite de commande, j'ai tapé, par hasard, FOR /? - il s'agit d'une technologie extra-terrestre ; je ne peux donc dévoiler mes sources - dans "Démarrer" + "Aide", j'ai cherché "ligne de commande"
-- @-salutations
Michel Claveau
Gilles LAURENT
"Pif" a écrit dans le message de news: | Hi,
Hello !
| I would like to create a command that read a "*.*" argument and then | apply a command for each file... But this jokers are note evaluated | and a only a string like any other. | | So can anyone tell me how to really evaluate the *.* in JScript | please ?
The sample script below evaluates the filenames of the current directory by using a regular expression. Filenames with blank character are *not* supported in the specified search pattern.
' declaration of variables Dim oRe, oFs, oSh, oFile Dim colFiles
' initialization of objects Set oRe = New RegExp Set oFs = CreateObject ("Scripting.FileSystemObject") Set oSh = CreateObject ("WSCript.shell")
' definition of a regular expression oRe.Pattern=WScript.Arguments(0) oRe.Pattern=Replace (oRe.Pattern, "*", ".*") oRe.Pattern=Replace (oRe.Pattern, ".", ".") oRe.Pattern=Replace (oRe.Pattern, " ", "|")
' gets the files from the current directory Set colFiles = oFs.GetFolder (".").Files For Each oFile In colFiles ' evaluates the filename against the regular expression If oRe.Test (oFile.Name) Then oSh.Run "notepad.exe " & oFile.Name,, True End If Next
--- Cut here : ProcessFiles.vbs ---
| Another problem is that when I apply to commands using the shell.run() | or shell.exec() methods, it seems to launch all process simultanously | and I would like that each process wait the end of the previous one ? | Any tip ?
The Run method of the Shell object is defined as below : Function Run (Command, [WindowStyle], [WaitOnReturn])
So, the third parameter 'WaitOnReturn' have to be set to True
-- Gilles LAURENT http://glsft.free.fr
"Pif" <Pif@discussions.microsoft.com> a écrit dans le message de
news:2C0F689A-CA9B-4F34-BECD-9B58EE0F5393@microsoft.com
| Hi,
Hello !
| I would like to create a command that read a "*.*" argument and then
| apply a command for each file... But this jokers are note evaluated
| and a only a string like any other.
|
| So can anyone tell me how to really evaluate the *.* in JScript
| please ?
The sample script below evaluates the filenames of the current directory
by using a regular expression. Filenames with blank character are *not*
supported in the specified search pattern.
' declaration of variables
Dim oRe, oFs, oSh, oFile
Dim colFiles
' initialization of objects
Set oRe = New RegExp
Set oFs = CreateObject ("Scripting.FileSystemObject")
Set oSh = CreateObject ("WSCript.shell")
' definition of a regular expression
oRe.Pattern=WScript.Arguments(0)
oRe.Pattern=Replace (oRe.Pattern, "*", ".*")
oRe.Pattern=Replace (oRe.Pattern, ".", ".")
oRe.Pattern=Replace (oRe.Pattern, " ", "|")
' gets the files from the current directory
Set colFiles = oFs.GetFolder (".").Files
For Each oFile In colFiles
' evaluates the filename against the regular expression
If oRe.Test (oFile.Name) Then
oSh.Run "notepad.exe " & oFile.Name,, True
End If
Next
--- Cut here : ProcessFiles.vbs ---
| Another problem is that when I apply to commands using the shell.run()
| or shell.exec() methods, it seems to launch all process simultanously
| and I would like that each process wait the end of the previous one ?
| Any tip ?
The Run method of the Shell object is defined as below :
Function Run (Command, [WindowStyle], [WaitOnReturn])
So, the third parameter 'WaitOnReturn' have to be set to True
| I would like to create a command that read a "*.*" argument and then | apply a command for each file... But this jokers are note evaluated | and a only a string like any other. | | So can anyone tell me how to really evaluate the *.* in JScript | please ?
The sample script below evaluates the filenames of the current directory by using a regular expression. Filenames with blank character are *not* supported in the specified search pattern.
' declaration of variables Dim oRe, oFs, oSh, oFile Dim colFiles
' initialization of objects Set oRe = New RegExp Set oFs = CreateObject ("Scripting.FileSystemObject") Set oSh = CreateObject ("WSCript.shell")
' definition of a regular expression oRe.Pattern=WScript.Arguments(0) oRe.Pattern=Replace (oRe.Pattern, "*", ".*") oRe.Pattern=Replace (oRe.Pattern, ".", ".") oRe.Pattern=Replace (oRe.Pattern, " ", "|")
' gets the files from the current directory Set colFiles = oFs.GetFolder (".").Files For Each oFile In colFiles ' evaluates the filename against the regular expression If oRe.Test (oFile.Name) Then oSh.Run "notepad.exe " & oFile.Name,, True End If Next
--- Cut here : ProcessFiles.vbs ---
| Another problem is that when I apply to commands using the shell.run() | or shell.exec() methods, it seems to launch all process simultanously | and I would like that each process wait the end of the previous one ? | Any tip ?
The Run method of the Shell object is defined as below : Function Run (Command, [WindowStyle], [WaitOnReturn])
So, the third parameter 'WaitOnReturn' have to be set to True
-- Gilles LAURENT http://glsft.free.fr
Gilles LAURENT
"Gilles LAURENT" a écrit dans le message de news:e0x$ | "Pif" a écrit dans le message de | news: || Hi, | | Hello ! | || I would like to create a command that read a "*.*" argument and then || apply a command for each file... But this jokers are note evaluated || and a only a string like any other. || || So can anyone tell me how to really evaluate the *.* in JScript || please ? | | The sample script below evaluates the filenames of the current | directory by using a regular expression. Filenames with blank | character are *not* supported in the specified search pattern. | | +++ Usage | cscript ProcessFiles.vbs <pattern> | | +++ Samples | >cscript ProcessFiles.vbs *.txt | >cscript ProcessFiles.vbs "*.txt *.bak" | >cscript ProcessFiles.vbs *.* | >cscript ProcessFiles.vbs "test1.txt test2.txt"
Oops ! after playing with my last script a patch is needed ;-)
--- Cut here : ProcessFiles.vbs ---
Option Explicit
' declaration of variables Dim oRe, oFs, oSh, oFile Dim colFiles
' initialization of objects Set oRe = New RegExp Set oFs = CreateObject ("Scripting.FileSystemObject") Set oSh = CreateObject ("WSCript.shell")
' definition of a regular expression oRe.Pattern=WScript.Arguments(0)
' gets the files from the current directory Set colFiles = oFs.GetFolder (".").Files For Each oFile In colFiles ' evaluates the filename against the regular expression If oRe.Test (oFile.Name) Then wscript.echo oFile.Name End If Next
--- Cut here : ProcessFiles.vbs ---
-- Gilles LAURENT http://glsft.free.fr
"Gilles LAURENT" <glsft@free.fr> a écrit dans le message de
news:e0x$QvrRHHA.4744@TK2MSFTNGP02.phx.gbl
| "Pif" <Pif@discussions.microsoft.com> a écrit dans le message de
| news:2C0F689A-CA9B-4F34-BECD-9B58EE0F5393@microsoft.com
|| Hi,
|
| Hello !
|
|| I would like to create a command that read a "*.*" argument and then
|| apply a command for each file... But this jokers are note evaluated
|| and a only a string like any other.
||
|| So can anyone tell me how to really evaluate the *.* in JScript
|| please ?
|
| The sample script below evaluates the filenames of the current
| directory by using a regular expression. Filenames with blank
| character are *not* supported in the specified search pattern.
|
| +++ Usage
| cscript ProcessFiles.vbs <pattern>
|
| +++ Samples
| >cscript ProcessFiles.vbs *.txt
| >cscript ProcessFiles.vbs "*.txt *.bak"
| >cscript ProcessFiles.vbs *.*
| >cscript ProcessFiles.vbs "test1.txt test2.txt"
Oops ! after playing with my last script a patch is needed ;-)
--- Cut here : ProcessFiles.vbs ---
Option Explicit
' declaration of variables
Dim oRe, oFs, oSh, oFile
Dim colFiles
' initialization of objects
Set oRe = New RegExp
Set oFs = CreateObject ("Scripting.FileSystemObject")
Set oSh = CreateObject ("WSCript.shell")
' definition of a regular expression
oRe.Pattern=WScript.Arguments(0)
' gets the files from the current directory
Set colFiles = oFs.GetFolder (".").Files
For Each oFile In colFiles
' evaluates the filename against the regular expression
If oRe.Test (oFile.Name) Then
wscript.echo oFile.Name
End If
Next
"Gilles LAURENT" a écrit dans le message de news:e0x$ | "Pif" a écrit dans le message de | news: || Hi, | | Hello ! | || I would like to create a command that read a "*.*" argument and then || apply a command for each file... But this jokers are note evaluated || and a only a string like any other. || || So can anyone tell me how to really evaluate the *.* in JScript || please ? | | The sample script below evaluates the filenames of the current | directory by using a regular expression. Filenames with blank | character are *not* supported in the specified search pattern. | | +++ Usage | cscript ProcessFiles.vbs <pattern> | | +++ Samples | >cscript ProcessFiles.vbs *.txt | >cscript ProcessFiles.vbs "*.txt *.bak" | >cscript ProcessFiles.vbs *.* | >cscript ProcessFiles.vbs "test1.txt test2.txt"
Oops ! after playing with my last script a patch is needed ;-)
--- Cut here : ProcessFiles.vbs ---
Option Explicit
' declaration of variables Dim oRe, oFs, oSh, oFile Dim colFiles
' initialization of objects Set oRe = New RegExp Set oFs = CreateObject ("Scripting.FileSystemObject") Set oSh = CreateObject ("WSCript.shell")
' definition of a regular expression oRe.Pattern=WScript.Arguments(0)
' gets the files from the current directory Set colFiles = oFs.GetFolder (".").Files For Each oFile In colFiles ' evaluates the filename against the regular expression If oRe.Test (oFile.Name) Then wscript.echo oFile.Name End If Next