+ Post New Thread
Results 1 to 5 of 5
Scripts Thread, Copying a file then renaming in Coding and Web Development; Hi All, I have a folder on the network and within it there is a single file, Picture.jpg. At regular ...
  1. #1
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    722
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40

    Copying a file then renaming

    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

  2. #2
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    722
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    Anyone??

  3. #3

    Join Date
    Jul 2009
    Posts
    288
    Thank Post
    8
    Thanked 43 Times in 37 Posts
    Rep Power
    16
    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.Argume nts(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

  4. Thanks to andydis from:

    Admiral208 (12th November 2010)

  5. #4

    Join Date
    Jul 2009
    Posts
    288
    Thank Post
    8
    Thanked 43 Times in 37 Posts
    Rep Power
    16
    It would be alot easier to have the files names as time%date.jpg

    as a batch , add it into your tasks on a server or something?

  6. Thanks to andydis from:

    Admiral208 (12th November 2010)

  7. #5
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    722
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    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

SHARE:
+ Post New Thread

Similar Threads

  1. File renaming
    By robinm in forum Windows
    Replies: 5
    Last Post: 3rd February 2009, 10:12 AM
  2. File copying at logon.
    By Bengaul in forum Scripts
    Replies: 8
    Last Post: 4th February 2008, 03:53 PM
  3. copying a file without admin
    By strawberry in forum Windows
    Replies: 2
    Last Post: 20th September 2007, 09:23 AM
  4. File Copying
    By Kwyjibo in forum Scripts
    Replies: 15
    Last Post: 9th May 2007, 03:30 PM
  5. copying a file at logon
    By browolf in forum Windows
    Replies: 1
    Last Post: 18th October 2005, 04:26 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •