Page 1 sur 1
[R] File Get Properties
Posté : mar. 25 nov. 2014 17:28
par DimVar
Bonjour à tous,
Je dois copier les fichiers d'un dossier, dans des dossiers nominatifs. Le nom de ces dossiers devra etre recupéré par la valeur de la colonne "auteur" (sous W7).
Auriez vous une piste pour récupérer la valeur de la colonne "Auteur" sous Windows ?
Merci à vous.
Cdlt, Dimvar.
[EDIT] J'ai trouvé une fonction pour cela, il ne me reste qu'à trouver l'algo qui me permettra de lister les fichiers et de les deplacer dans un dossier nominatif.
Fonction
► Afficher le texte
;===============================================================================
; Function Name: GetExtProperty($sPath,$iProp)
; Description: Returns an extended property of a given file.
; Parameter(s): $sPath - The path to the file you are attempting to retrieve an extended property from.
; $iProp - The numerical value for the property you want returned. If $iProp is is set
; to -1 then all properties will be returned in a 1 dimensional array in their corresponding order.
; The properties are as follows:
; Name = 0
; Size = 1
; Type = 2
; DateModified = 3
; DateCreated = 4
; DateAccessed = 5
; Attributes = 6
; Status = 7
; Owner = 8
; Author = 9
; Title = 10
; Subject = 11
; Category = 12
; Pages = 13
; Comments = 14
; Copyright = 15
; Artist = 16
; AlbumTitle = 17
; Year = 18
; TrackNumber = 19
; Genre = 20
; Duration = 21
; BitRate = 22
; Protected = 23
; CameraModel = 24
; DatePictureTaken = 25
; Dimensions = 26
; Width = 27
; Height = 28
; Company = 30
; Description = 31
; FileVersion = 32
; ProductName = 33
; ProductVersion = 34
; Requirement(s): File specified in $spath must exist.
; Return Value(s): On Success - The extended file property, or if $iProp = -1 then an array with all properties
; On Failure - 0, @Error - 1 (If file does not exist)
; Author(s): Simucal (
Simucal@gmail.com)
; Note(s):
;
;===============================================================================
Re: [..] file get properties
Posté : mar. 25 nov. 2014 21:16
par DimVar
@Walkson :Oui, c'etait ca (voir EDIT ci dessus), merci. Vous avez suppr votre reponse ?
Voila ce à quoi j'ai pensé :
► Afficher le texte
Code : Tout sélectionner
#include <MsgBoxConstants.au3>
#include <File.au3>
Global $A, $aFile; declaration
$path = _path(); recuperation du path dossier
$aFile = _FileListToArrayRec ($path); liste les fichiers du dossier
_ArrayDisplay ($aFile); pour verif
$A = _GetExtProperty("c:\savserver\msexcel\132846608.xls", 20); test de la fonction get property
Func _path()
; Create a constant variable in Local scope of the message to display in FileSelectFolder.
Local Const $sMessage = "Choisir un dossier"
; Display an open dialog to select a file.
Local $sFileSelectFolder = FileSelectFolder($sMessage, "")
If @error Then
; Display the error message.
MsgBox($MB_SYSTEMMODAL, "", "Pas de dossier selectionne")
Else
; Display the selected folder.
MsgBox($MB_SYSTEMMODAL, "", "Vous avez choisi ce dossier :" & @CRLF & $sFileSelectFolder)
EndIf
Return $sFileSelectFolder
EndFunc ;==>Example
;===============================================================================
; Function Name: GetExtProperty($sPath,$iProp)
; Description: Returns an extended property of a given file.
; Parameter(s): $sPath - The path to the file you are attempting to retrieve an extended property from.
; $iProp - The numerical value for the property you want returned. If $iProp is is set
; to -1 then all properties will be returned in a 1 dimensional array in their corresponding order.
; The properties are as follows:
; Name = 0
; Size = 1
; Type = 2
; DateModified = 3
; DateCreated = 4
; DateAccessed = 5
; Attributes = 6
; Status = 7
; Owner = 8
; Author = 9
; Title = 10
; Subject = 11
; Category = 12
; Pages = 13
; Comments = 14
; Copyright = 15
; Artist = 16
; AlbumTitle = 17
; Year = 18
; TrackNumber = 19
; Genre = 20
; Duration = 21
; BitRate = 22
; Protected = 23
; CameraModel = 24
; DatePictureTaken = 25
; Dimensions = 26
; Width = 27
; Height = 28
; Company = 30
; Description = 31
; FileVersion = 32
; ProductName = 33
; ProductVersion = 34
; Requirement(s): File specified in $spath must exist.
; Return Value(s): On Success - The extended file property, or if $iProp = -1 then an array with all properties
; On Failure - 0, @Error - 1 (If file does not exist)
; Author(s): Simucal (Simucal@gmail.com)
; Note(s):
;
;===============================================================================
Func _GetExtProperty($sPath, $iProp)
Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
$iExist = FileExists($sPath)
If $iExist = 0 Then
SetError(1)
Return 0
Else
$sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
$sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
$oShellApp = ObjCreate ("shell.application")
$oDir = $oShellApp.NameSpace ($sDir)
$oFile = $oDir.Parsename ($sFile)
If $iProp = -1 Then
Local $aProperty[35]
For $i = 0 To 34
$aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i)
Next
Return $aProperty
Else
$sProperty = $oDir.GetDetailsOf ($oFile, $iProp)
If $sProperty = "" Then
Return 0
Else
Return $sProperty
EndIf
EndIf
EndIf
EndFunc ;==>_GetExtProperty
J'aurais juste besoin d'un cp de pouce pour la boucle qui va recuperer les noms de fichiers dans le tableau (suis null en ForNext)
Merci à vous.
Re: [..] file get properties
Posté : mar. 25 nov. 2014 21:35
par jguinch
C'est où que tu bloques ? La simple boucle while ?
► Afficher le texte
Code : Tout sélectionner
$aFile = _FileListToArray ($path); liste les fichiers du dossier
If @error Then Exit
For $i = 1 To $aFile[0]
$sAuthor = _GetExtProperty($path & "\" & $aFile[$i], 8) ; Récupère l'auteur de pour chaque fichier
If String($sAuthor) <> "0" Then
ConsoleWrite( "Fichier : " & $path & "\" & $aFile[$i] & @TAB & "Auteur : " & $sAuthor )
FileCopy( $path & "\" & $aFile[$i], "\\server\share\" & $sAuthor & "\")
EndIf
Next
Re: [..] File Get Properties
Posté : mer. 26 nov. 2014 09:27
par DimVar
Bonjour Jguinch,
C'est bête, mais j'ai toujours eu du mal avec les boucle FOR avec tableau... Et n'ayant pas codé depuis plus d'un an, j'ai zappé les qq notions que j'avais acquise à ce niveau.( trop l'habitude d'un while avec exitloop)
Sinon, oui, c'est juste ce dont j'avais besoin. Merchi.
Je clos.
Cdlt, Dimvar.
Re: [R] File Get Properties
Posté : mer. 26 nov. 2014 12:14
par walkson
Bonjour DimVar
Excusez moi, au lieu de supprimer mon post j'aurais du mettre [EDIT] je suis trop lent..

Re: [R] File Get Properties
Posté : mer. 26 nov. 2014 13:01
par DimVar
Pas de souchi...