Jump to content

Recommended Posts

Posted

Hi All,

 

I have a folder on the network and within it there is a single file, Picture.jpg. At regular intervals of about 90 mins, I need to copy the file to another location and rename it to Picture1.jpg. After another 90 mins, I need to copy and rename to Picture2.jpg. etc etc...

 

Can this be done and if so... how??

 

Im sure some of you clever people can do this.

 

Thanks in advance.

 

James

Posted

VBS OR BATCH FILE?

 

BELOW IS A VBS

 

'Renames a file to start with a number. Automatically increments the number

'based on the highest existing number in the directory. Won't rename a file

'if it already starts with a number which matches the target pattern.

'Although you can drop a single file on this script, the most common use

'is to renumber all files in a folder. While you CAN'T drop a folder on the

'script, running the script without arguments will toggle a right-click

'option on directories to enable name-sorted numbering of all files

'(except previously-numbered files) in that directory

 

Option Explicit

Const NUMBER_STEP = 10 'File numbering will increment by this amount

Const NUMBER_DIGITS = 4 'Numbers will have this many digits (with leading zeros)

Const NUMBER_DELIMITER = "-" 'The character that follows the leading number

Main

 

Sub Main

Dim oFolder, oFile, fs, lngNumber

Set fs = CreateObject("Scripting.FileSystemObject")

If WScript.Arguments.Count = 0 Then ToggleRightClick

If Wscript.Arguments.Count <> 1 Then Exit Sub

If Not fs.FileExists(WScript.Arguments(0)) Then Exit Sub

Set oFolder = fs.GetFolder(fs.GetParentFolderName(WScript.Arguments(0)))

Set oFile = fs.GetFile(WScript.Arguments(0))

'Don't number a file if it's already been numbered!

If Mid(oFile.Name, NUMBER_DIGITS + 1, 1) = NUMBER_DELIMITER Then

If IsNumeric(Left(oFile.Name, NUMBER_DIGITS)) Then

Exit Sub

End If

End If

'Find the highest numbere file in the directory ...

lngNumber = HighestNumber(oFolder)

'... and rename our file to start with the next number

oFile.Name = Right(String(NUMBER_DIGITS, "0") & Cstr(lngNumber + NUMBER_STEP), 4) & NUMBER_DELIMITER & oFile.Name

End Sub

 

Function HighestNumber(objFolder)

Dim fils, fil, fols, fol, lngNumber, strName

On Error Resume Next

'Get each file in turn

lngNumber = 0

Set fils = objFolder.Files

If Err.Number = 0 Then

For Each fil In fils

strName = fil.Name

If Len(strName) > NUMBER_DIGITS + 5 Then

If Mid(strName, NUMBER_DIGITS + 1, 1) = NUMBER_DELIMITER Then

If IsNumeric(Left(strName, NUMBER_DIGITS)) Then

If CLng(Left(strName, NUMBER_DIGITS)) > lngNumber Then

lngNumber = CLng(Left(strName, NUMBER_DIGITS))

End If

End If

End If

End If

Next

End If

HighestNumber = lngNumber

End Function

 

Sub Status(strMessage)

If Lcase(Right(Wscript.FullName, 12)) = "\cscript.exe" Then

Wscript.Echo strMessage

End If

End Sub

 

Sub ToggleRightClick()

' Adds or deletes this script as a right-click option for "Directory"

Dim ws, fs, strKey

Set ws = CreateObject("Wscript.Shell")

Set fs = CreateObject("Scripting.FileSystemObject")

 

On Error Resume Next

 

strKey = "HKEY_CLASSES_ROOT\Directory\shell\" & fs.GetBaseName(WScript.ScriptName) & "\"

If RightClickEnabled(strKey) Then

ws.RegDelete strKey & "command\"

ws.RegDelete strKey

MsgBox "Right-Click option on folders for this script has been REMOVED",,fs.GetBaseName(WScript.ScriptName)

Else

ws.RegWrite strKey & "command\", _

"cmd.exe /c for /f ""delims="" %%x in ('dir /b /s /on ""%1""') " _

& "do cscript.exe """ & Wscript.ScriptFullName & """ ""%%x""" _

, "REG_EXPAND_SZ"

MsgBox "Right-Click option on folders for this script has been ADDED",,fs.GetBaseName(WScript.ScriptName)

End If

End Sub

 

Function RightClickEnabled(strKey)

Dim ws, fs

Set ws = CreateObject("Wscript.Shell")

On Error Resume Next

RightClickEnabled = Eval("" <> ws.RegRead(strKey & "command\"))

End Function

  • Thanks 1
Posted

Andydis, many thanks for this. Let me explain what i want to use this for and it might help you to understand (gets a bit complicated). I think I need a combination of VBS and a Batch to complete what I want.

 

We are just about to start the building works for a new school (BSF). I have set up a webcam pointing at the works which takes a picture every 10 seconds and uploads it to our sharepoint website. The sharepoint site is hosted off site at out LA so I have had to map a drive to the folder on the sharepoint site and use YAWCAM to take a picture and save it it this shared network drive. This image is always overwritten. This means that I can insert an image into our site called Picture1.jpg and as YAWCAM overwrites the image every 10 seconds, the website also updates itself. This part of the process works very well. for those of you who want to see, go here. This image updates every 10 seconds.

 

The next thing i want to do is create a timelapse of the event but dont want a picture every 10 seconds (over a 2 year period, i would have millions of images), only every 90 mins. So I want to copy the file from the sharepoint folder which is mapped locally on my machine. But because it always has the same filename, I need it to be renamed to Picture1.jpg. Then 90 mins later copy the latest image and rename it to Picture2.jpg. All of this needs to be done automatically so I might need a VBS to rename the files and a batch to run on the scheduled tasks on the machine where the webcam is attached.

 

I understand this is quite complicated but im sure it can be done. Im just no good with scripts or creating them...

 

TIA

 

James

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • 43 When would you like EduGeek EDIT 2025 to be held?

    1. 1. Select a time period you can attend


      • I can make it in June\July
      • I can make it in August\Sept
      • Other time period. Comment below
      • Either time

×
×
  • Create New...