Question Locked

Script Help

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can someone help me out with a vbs script. I have this script. It displays the directory I'm looking for and allows me to filter the files. I need it to allow me to save the files that I select instead of just echoing back my choices. I also need it to block the user from being able to delete from that directory. Thanks in advance for any assistance in this matter.

Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "JPEG|*.jpg|BitMap|*.bmp|All Files|*.*"
objDialog.Flags = &H0200
objDialog.FilterIndex = 3
objDialog.InitialDir = "\\server\share"
intResult = objDialog.ShowOpen

If intResult = 0 Then
Wscript.Quit
Else
arrFiles = Split(objDialog.FileName, " ")
For i = 1 to Ubound(arrFiles)
strFile = arrFiles(0) & arrFiles(i)
Wscript.Echo strFile
Next
End If

4 replies

by larryd4

Well not allowing the users to delete from a network share is a rights setting on that share. You will have to set the correct level of permission to not allow them to delete.

As for the script you will have to bind to the Scripting.FileSystemObject to allow you to copy, move, or delete the found file.

Here is a slightly older example of a script I wrote that scans my servers "user" directory and deletes any music file off the server.

This script was scheduled to run on the server as a scheduled task under an admin account.
==================================
'On Error Resume Next

'Sets UserPath for binding to the users folder on server
'Sets LogPath for usin in creating, opening, and appending log file.
UserPath = "F:\"
LogPath = "C:\srvscripts\media\medialog.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Folder = objFSO.GetFolder(UserPath)

'If statement to check for existing file and if not their create it.
If objFSO.FileExists(LogPath) Then
Else
Set objCreate = objFSO.CreateTextFile(LogPath)
objCreate.Close
End If

'Opening log file for appending.
Set objLogFile = objFSO.OpenTextFile(LogPath, 8)

'writes the date to show where the new days processing starts.
objLogFile.WriteLine Now

'Calls the Sub to enumerate through folders and files
ShowSubFolders Folder

'Closes the open log file and exits the Script
objLogFile.Close

'Quiting Script
WScript.Quit

'=========================================================
' ShowSubFolders Subset
'=========================================================
Sub ShowSubFolders(Folder)

' For loop to enumerate through folders and subfolders
For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
' For Loop to enumerate through files in folder.
For Each objFile In colFiles
' If statement to check for audio files and delete and log file.
If Right(objFile.Name,4) = ".mp3"_
Or Right(objFile.Name,4) = ".wav"_
Or Right(objFile.Name,4) = ".wma"_
Or Right(objFile.Name,4) = ".ogg"_
Or Right(objFile.Name,4) = ".aac" Then
' Writes the date and the file path of file about to be deleted
objLogFile.WriteLine Now & "," & objFile.Path
' Deletes the file
objFSO.DeleteFile(objFile.Path)
End If
Next
' Calling Sub again for subfolders with in folder.
ShowSubFolders Subfolder
Next
End Sub

by gpenunuri

Thanks Larry for the reply. I will see if I can pick out what I need. Let me clarify what I need exactly. I need the users to launch the script and select the files that they need and have the script copy the files to a directory of their choice.

by larryd4

Oooo Ok thats a lot different, I didn't see the requirement to have them choose what they need.

Thats going to be a much larger code project, especially in VBS...

I would probably use an IE instance to show the user the found files, but you will have to know something about html form building to get the choices the user makes out of IE, to make the rest of the script work.

Problem is currently VBS does not have much support for user interfaces except for the Input and Message boxes.

I don't know how big of a file list you might generate but putting a large list of files in a Message Box may get messy.

Any chance you could do this with VBS in a ASP page?

Other wise I would probably go with a VB application rather then a script.

This discussion is closed to new replies.