Question lecture fichier et creation de dossier

Plus d'informations
il y a 13 ans 3 semaines #14737 par Matthew BETTON
Effectivement... je constate la même chose ^^ Je regarde...<br><br>Message édité par: Matthew BETTON, à: 29/04/13 11:37

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 3 semaines #14738 par Matthew BETTON
Ok, retire le '-Name' :

[code:1]
Get-ChildItem -Path '\\server\d$' -recurse | Where-Object { $_.PSIsContainer } | Foreach {
New-Item -Type Directory -Path ($_.FullName -replace \&quot;\\d\$\&quot;, \&quot;\e$\&quot;«»)}
[/code:1]

Refais le test et dis moi tout ;)

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 3 semaines #14739 par stas
Magnifique :lol: :)
Merci bcp

donc le -Name c'est ce qui allait chercher dans le pipe?
[code:1]
Directory: \\server\d$

Name
PUBLIC
test
USERDATA
[/code:1]
et il créer aussi via la directory?

donc il fait un doublon? ai-je bien compris?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 3 semaines #14740 par Matthew BETTON
Le chemin précisé via le paramètre '-Path' n'existe pas : il est donc créé. Le nom spécifié via '-Name' est ensuite créé dans le chemin... PowerShell faisait donc ce qu'on lui demandait :)

[code:1]
PS&gt;Get-Help New-Item -Parameter Name

-Name &lt;string&gt;
Spécifie le nom du nouvel élément. Vous pouvez utiliser ce paramètre pour spécifier le nom du nouvel élément ou
inclure le nom de la valeur du paramètre Path.
[/code:1]

Le pipe transmet à la commande suivante chaque élément renvoyé par la commande précédente (créé donc un flux de données).

Le '$_' dans le 'foreach' (dans notre cas, il s'agit de l'alias de 'Foreach-Object') correspond à la variable automatique qui représente chaque élément ainsi transféré via le pipe.

Ici, il s'agit d'objets issu de la classe 'System.IO.DirectoryInfo' (Ceux résultants de la Cmdlet 'Get-ChildItem', filtrés ensuite sur le type 'Container' via le 'Where-Object', donc uniquement des répertoires transmis à New-Item).

Si nous faisons un 'Get-Member' sur l'un de ces objets 'System.IO.DirectoryInfo' :

[code:1]
PS&gt;Get-ChildItem d:\ | Get-Member


TypeName: System.IO.DirectoryInfo

Name MemberType Definition
----

Mode CodeProperty System.String Mode{get=Mode;}
Create Method System.Void Create(System.Security.AccessControl.DirectorySecurity director...
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
CreateSubdirectory Method System.IO.DirectoryInfo CreateSubdirectory(string path), System.IO.Director...
Delete Method System.Void Delete(), System.Void Delete(bool recursive)
Equals Method bool Equals(System.Object obj)
GetAccessControl Method System.Security.AccessControl.DirectorySecurity GetAccessControl(), System....
GetDirectories Method System.IO.DirectoryInfo[] GetDirectories(string searchPattern), System.IO.D...
GetFiles Method System.IO.FileInfo[] GetFiles(string searchPattern), System.IO.FileInfo[] G...
GetFileSystemInfos Method System.IO.FileSystemInfo[] GetFileSystemInfos(string searchPattern), System...
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetObjectData Method System.Void GetObjectData(System.Runtime.Serialization.SerializationInfo in...
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
MoveTo Method System.Void MoveTo(string destDirName)
Refresh Method System.Void Refresh()
SetAccessControl Method System.Void SetAccessControl(System.Security.AccessControl.DirectorySecurit...
ToString Method string ToString()
PSChildName NoteProperty System.String PSChildName=Computacenter
PSDrive NoteProperty System.Management.Automation.PSDriveInfo PSDrive=D
PSIsContainer NoteProperty System.Boolean PSIsContainer=True
PSParentPath NoteProperty System.String PSParentPath=Microsoft.PowerShell.Core\FileSystem::«»D:\
PSPath NoteProperty System.String PSPath=Microsoft.PowerShell.Core\FileSystem::«»D:\Computacenter
PSProvider NoteProperty System.Management.Automation.ProviderInfo PSProvider=Microsoft.PowerShell.C...
Attributes Property System.IO.FileAttributes Attributes {get;set;}
CreationTime Property System.DateTime CreationTime {get;set;}
CreationTimeUtc Property System.DateTime CreationTimeUtc {get;set;}
Exists Property System.Boolean Exists {get;}
Extension Property System.String Extension {get;}
FullName Property System.String FullName {get;}
LastAccessTime Property System.DateTime LastAccessTime {get;set;}
LastAccessTimeUtc Property System.DateTime LastAccessTimeUtc {get;set;}
LastWriteTime Property System.DateTime LastWriteTime {get;set;}
LastWriteTimeUtc Property System.DateTime LastWriteTimeUtc {get;set;}
Name Property System.String Name {get;}
Parent Property System.IO.DirectoryInfo Parent {get;}
Root Property System.IO.DirectoryInfo Root {get;}
BaseName ScriptProperty System.Object BaseName {get=$this.Name;}
ReparsePoint ScriptProperty System.Object ReparsePoint {get=if($this.Attributes -band [IO.FileAttribute...
[/code:1]

... nous retrouvons notament les méthodes et les proriétés de l'objet, dont la propriété 'FullName'.

C'est cette propriété que nous transformons via l'opérateur '-Replace'.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 3 semaines #14742 par stas
UN TRES GRAND MERCI

super les explications surtout pour un novice comme moi.<br><br>Message édité par: fabgr, à: 4/05/13 10:33

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.043 secondes
Propulsé par Kunena