Question Function lock/unlock
- raphi67
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 2
- Remerciements reçus 0
il y a 14 ans 1 mois #11047
par raphi67
Function lock/unlock a été créé par raphi67
Bonjour,
Je souhaite copier un fichier d'un point A a un point B et verrouiller le fichier sur le point B tant que la copie n'est pas terminée.
Pour le moment j'ai ceci, mais le unlock ne fonctionne pas.
Pourrais je avoir votre avis ? Merci
Copy-Item -path C:\toto.txt -destination D:\toto.txt | lockfile D:\toto.txt
unlock
function lockfile
{
Param($path)
$lock = [System.io.File]::Open( $path, 'Open', 'Read', 'None')
\"file locked\"
}
function unlock
{
$lock.Close()
\"file unlocked\"
}
Je souhaite copier un fichier d'un point A a un point B et verrouiller le fichier sur le point B tant que la copie n'est pas terminée.
Pour le moment j'ai ceci, mais le unlock ne fonctionne pas.
Pourrais je avoir votre avis ? Merci
Copy-Item -path C:\toto.txt -destination D:\toto.txt | lockfile D:\toto.txt
unlock
function lockfile
{
Param($path)
$lock = [System.io.File]::Open( $path, 'Open', 'Read', 'None')
\"file locked\"
}
function unlock
{
$lock.Close()
\"file unlocked\"
}
Connexion ou Créer un compte pour participer à la conversation.
- Richard Lazaro
- Hors Ligne
- Membre platinium
-
Réduire
Plus d'informations
- Messages : 530
- Remerciements reçus 0
il y a 14 ans 1 mois #11049
par Richard Lazaro
Think-MS : (Get-Life).Days | %{ Learn-More }
\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein
Réponse de Richard Lazaro sur le sujet Re:Function lock/unlock
Bonjour,
Tu initialises ta variable $lock dans la fonction lockfile, si on se refere aux principes des scopes, alors la fonction unlockfile ne connaitra pas cette variable sauf si tu la passes en parametre.
Bien Cordialement,
Richard Lazaro.
Tu initialises ta variable $lock dans la fonction lockfile, si on se refere aux principes des scopes, alors la fonction unlockfile ne connaitra pas cette variable sauf si tu la passes en parametre.
Bien Cordialement,
Richard Lazaro.
Think-MS : (Get-Life).Days | %{ Learn-More }
\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.073 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les initiés
- Function lock/unlock