PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Using VBscript to perform a file pattern search
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Using VBscript to perform a file pattern search

Réponse
 
LinkBack Outils de la discussion
Vieux 26/11/2007, 18h04   #1
DeJae
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Using VBscript to perform a file pattern search

Hello All,

I am new at using vbscript. I have been using .bat files to try to
administer our file server, but for what I am trying to do right now, they
are not robust enough.

My goal is to delete files that are .tmp files and files that have no
extension which are created by Excel. These files with no extensions (created
by Excel) are my biggest concern. These files are created when users who only
have r/w perms go in to modify a spreadsheet on the server and click save.
The temp files cannot be automatically deleted as designed, if the users like
the permissions to delete. So without granting users perms they are not
authorized to have, I am looking into creating a script that will go in and
search for these particular files through all subdirectories that would look
like this: C7F9F830

These temp files are always 8 characters long and have no extension. Is
there a way to perform a search through all subdirectories for this file type
that has no extension?
  Réponse avec citation
Vieux 26/11/2007, 19h50   #2
pooradmin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using VBscript to perform a file pattern search

On Nov 26, 1:04 pm, DeJae <De...@discussions.microsoft.com> wrote:
> Hello All,
>
> I am new at using vbscript. I have been using .bat files to try to
> administer our file server, but for what I am trying to do right now, they
> are not robust enough.
>
> My goal is to delete files that are .tmp files and files that have no
> extension which are created by Excel. These files with no extensions (created
> by Excel) are my biggest concern. These files are created when users who only
> have r/w perms go in to modify a spreadsheet on the server and click save.
> The temp files cannot be automatically deleted as designed, if the users like
> the permissions to delete. So without granting users perms they are not
> authorized to have, I am looking into creating a script that will go in and
> search for these particular files through all subdirectories that would look
> like this: C7F9F830
>
> These temp files are always 8 characters long and have no extension. Is
> there a way to perform a search through all subdirectories for this file type
> that has no extension?


This would be a nice one-liner with powershell. can remove the whatif
when comfortable with it.

dir f:\temp\ -R | where { $_.name.length -eq 8 } | % { del $_.fullname
-whatif }

-J
www.pooradmin.com
  Réponse avec citation
Vieux 26/11/2007, 20h11   #3
Pegasus \(MVP\)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using VBscript to perform a file pattern search


"DeJae" <DeJae@discussions.microsoft.com> wrote in message
news:AF2F3280-8294-4552-94FB-364AF85270DE@microsoft.com...
> Hello All,
>
> I am new at using vbscript. I have been using .bat files to try to
> administer our file server, but for what I am trying to do right now, they
> are not robust enough.
>
> My goal is to delete files that are .tmp files and files that have no
> extension which are created by Excel. These files with no extensions
> (created
> by Excel) are my biggest concern. These files are created when users who
> only
> have r/w perms go in to modify a spreadsheet on the server and click save.
> The temp files cannot be automatically deleted as designed, if the users
> like
> the permissions to delete. So without granting users perms they are not
> authorized to have, I am looking into creating a script that will go in
> and
> search for these particular files through all subdirectories that would
> look
> like this: C7F9F830
>
> These temp files are always 8 characters long and have no extension. Is
> there a way to perform a search through all subdirectories for this file
> type
> that has no extension?


And here is a VB Script solution. Chatty, as usual, but it should
work. Remove the single quote at the start of Line 32 to activate it.

Dim ObjWshShell, objArgs, objFSO
Dim Folder, FileCount

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ObjWshShell = WScript.CreateObject("WScript.Shell")
Set objArgs = WScript.Arguments

FileCount = 0
Folder = ObjWshShell.CurrentDirectory
If objArgs.Count > 0 Then Folder = objArgs(0)
ProcessFolder Folder

WScript.Echo Chr(10) & FileCount & " file(s) deleted"
Set objFSO = Nothing

'------------------------------
'Process one folder recursively
'------------------------------
Sub ProcessFolder(Folder)
' Dim objFSO, objFile, objFldr, objSFldr, path
Dim objFile, objFldr, objSFldr, path

WScript.echo "Processing " & Folder
WScript.Sleep(1000)
' Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFldr = objFSO.GetFolder(Folder)

For Each objFile In objFldr.Files
If InStr(objFile.Name, ".") = 0 And Len(objFile.Name) = 8 Then
FileCount = FileCount + 1
WScript.Echo objFile.Name
' objfile.Delete
End If
Next

' Process subdirectories
For Each objSFldr In objFldr.SubFolders
If Right(Folder,1) = "\" Then
path = Folder & objSFldr.name
Else
path = Folder & "\" & objSFldr.Name
End If
ProcessFolder path
Next
End Sub


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12901 seconds with 11 queries