Webmaster Forum

Go Back   Webmaster Forum > Scripting/Programming & Debugging > ASP & VBScript Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

ASP & VBScript Forum Need help from a webmaster with ASP or VBScript, you may ask in this forum?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-03-2008, 10:02 PM
fotoart fotoart is offline
Junior Member
 
Join Date: Aug 2008
Posts: 1
fotoart is an unknown quantity at this point
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default how to check if a file is in use

hello everyone

Im using a vbs file to move a list of files in a folder to another folder.
However I find that if any of the file in the folder is in use(active because used by another program) any file below that is not moved.

How can I move all the files that are not in use?

any help in the right direction will be appreciated

-----------------
this is the code im using

Option Explicit
Sub MoveFiles(myFileType)

Dim FSO, myNewFolder, xM, xD, xY, myFolderName, myPath, myDay, myFolder

Set FSO = CreateObject("Scripting.FileSystemObject")

myDay = DateAdd("d", -1, Date)
xM = MonthName(Month(myDay))
xD = Right("0" & Day(myDay),2)
xY = Year(myDay)

myPath = FSO.GetParentFolderName(WScript.ScriptFullName)
myFolder = FSO.GetFolder(myPath).Name
if myFolder = "" then
myFolderName = myFolder &"DFM" & "_" & xD & "_" & xM & "_" &xY
else
myFolderName = myFolder & "_" & xD & "_" & xM & "_" &xY
end if
myNewFolder = myPath & "\" & myFolderName

fso.CreateFolder(myNewFolder)
FSO.MoveFile myPath & "\" & "*." & myFileType, myNewFolder &"\"

End Sub
Call MoveFiles ("mp3")
-----------------------------------

thanks

ahmed
Reply With Quote

This ad is part of our Revenue Sharing program
  #2 (permalink)  
Old 10-07-2008, 10:38 AM
Telonius Telonius is offline
Junior Member
 
Join Date: Oct 2008
Posts: 7
Telonius is an unknown quantity at this point
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Arrow

See the Modifications

Important ¡¡¡¡¡ >>>>> On error Resume next
------------------------------------------------

Option Explicit



Sub MoveFiles(myFileType)

On Error Resume Next ' ¡¡¡¡¡IMPORTANT....IMPORTANT...IMPORTANT....¡¡¡ ¡¡


Dim FSO, myNewFolder, xM, xD, xY, myFolderName, myPath, myDay, myFolder
Dim ficher, ficherCount, ficher1, GetAnExtension ' NEW VARIABLES

Set FSO = CreateObject("Scripting.FileSystemObject")

myDay = DateAdd("d", -1, Date)
xM = MonthName(Month(myDay))
xD = Right("0" & Day(myDay),2)
xY = Year(myDay)

myPath = FSO.GetParentFolderName(WScript.ScriptFullName)
myFolder = FSO.GetFolder(myPath).Name

if myFolder = "" then
myFolderName = myFolder &"DFM" & "_" & xD & "_" & xM & "_" &xY
else
myFolderName = myFolder & "_" & xD & "_" & xM & "_" &xY
end if
myNewFolder = myPath & "\" & myFolderName



fso.CreateFolder(myNewFolder)



''******************* MODIFICATIONS *********************
' ************* READ FILE AT FILE **********************

Set ficher = fso.GetFolder(myPath )
Set ficherCount = ficher.Files

For Each ficher1 in ficherCount
GetAnExtension = fso.GetExtensionName(ficher1.name)
Err.Clear ' GESTION ERRORS
If GetAnExtension = myFileType Then

FSO.MoveFile myPath & "\" & ficher1.Name , myNewFolder &"\"

End If

'
If Err.Number =70 Then
MsgBox "This file is in use ..."&Chr(13)& myPath & "\" & ficher1.Name
End If



Next


'FSO.MoveFile myPath & "\" & "*." & myFileType, myNewFolder &"\"
End Sub



Call MoveFiles ("mp3")

Last edited by Telonius : 10-07-2008 at 02:11 PM. Reason: Mensaje Errors
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBscript to check folder & send email if file exists along with path mahesha_babu ASP & VBScript Forum 0 06-30-2008 12:39 PM
I got something good please check it out.... Roger123 All other Scripting/Programming items 0 10-30-2007 02:03 PM
Check this out detoam Webmasters Lounge/General Chat 3 03-03-2007 01:32 AM


All times are GMT. The time now is 06:11 AM.


Creative Commons License
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30