OVH Cloud OVH Cloud

joker *.* and concurrent task calls

8 réponses
Avatar
Pif
Hi,

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 ?

Thanks a lot

8 réponses

Avatar
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 ?
Avatar
MC
See FOR /?

--
@-salutations

Michel Claveau
Avatar
Pif
Bonjour, peux tu développer un peu ?
Merci.

NB : avez vous de bonnes docs ou tutoriels sur la syntaxe de ce langage et
surtout les fonctions systèmes....

Merci !

"MC" wrote:

See FOR /?

--
@-salutations

Michel Claveau





Avatar
MC
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

:TRAITEMENT
echo "Nom du fichier : ",%*
:: xcopy "%*" "Z:receptexemple" ::exemple traitement1
:: c:proganalyz.exe "%*" ::exemple traitement2
goto :EOF

--
@-salutations

Michel Claveau

Avatar
Pif
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

:TRAITEMENT
echo "Nom du fichier : ",%*
:: xcopy "%*" "Z:receptexemple" ::exemple traitement1
:: c:proganalyz.exe "%*" ::exemple traitement2
goto :EOF

--
@-salutations

Michel Claveau






Avatar
MC
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"

--
@-salutations

Michel Claveau



Avatar
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.

+++ 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"

--- 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)
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
Avatar
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)

oRe.Pattern=Replace (oRe.Pattern, ".", ".")
oRe.Pattern=Replace (oRe.Pattern, "*", ".*")
oRe.Pattern=Replace (oRe.Pattern, " ", "|")
oRe.Pattern="^" & 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
wscript.echo oFile.Name
End If
Next

--- Cut here : ProcessFiles.vbs ---

--
Gilles LAURENT
http://glsft.free.fr