Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

Creating a folder based on today's date and copying from another folder

$
0
0
Hi

I have the following VB Scripts that work but I would like to edit it so it is just one VB Script instead of 2. The first one shows a pop up message to show the user don't use the screen as as it's running. At the moment at every login of the PC this is run (Shows a timed pop up message for 1 minute)

Dim counter
Dim oShell
counter = 60
Set oShell= CreateObject("Wscript.Shell")
While counter > 0

oShell.Popup " Left " & counter & " Seconds",1,"Please wait..."
counter = counter-1
CreateObject("WScript.Shell").Popup "Copying folder... Notepad will start automatically", 1, "Please wait..."
Wend

I have set it to 1 min as this I see this enough for the script to copy the folder. There is another vbscript running with the code (All this is doing is creating a folder based on today's date and copying contents from one folder to another folder as a backup. Now what I want really is to combine these 2 scripts together. However, as this is run at startup I would like script not run again if the folder exists. (Which the code does have that line in). For example a start of a new day the PC is turned on and the script runs and the user is then prompted to leave the PC for a minute untill the copy has finished and then the user can use the PC. However, if the user then logs off and then logs back in (or reboots) I would like the script to ignore the timer and the copy of the folder and just open Notepad as normal. Here is the code:

'Declare the variables. Not mandatory but a best practice
Dim dtmValue, strDate, strTime
Dim objFSO

'Create the file system object for creating folders
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get current time in to a variable
dtmValue = Now()

'use date /time part functions to create the folder names as required
'Assuming that you are creating these folders in C:\
strDate = "C:\DATA\"& Day(dtmValue) & "_" & Month(dtmValue) & "_" & Year(dtmValue)
strTime = strDate & "\" & Hour(dtmValue) & "-" & Minute(dtmValue) & "-" & Second(dtmValue)

'Wscript.Echo strDate
'Wscript.Echo strTime

'Create the folders using objFSO
'First check if folders exists and create only they dont exist
if objFSO.FolderExists(strDate) Then
if not objFSO.FolderExists(strTime) Then
'objFSO.CreateFolder(strTime)
End If
Else
'Create Top level folder first
objFSO.CreateFolder(strDate)

'Create subfolder
'objFSO.CreateFolder(strTime)

Set FSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "C\Data\1\*.*",(strDate)
objFSO.CopyFile "C\Data\1\*.*",(strDate)


Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Exec("C:\Windows\Notepad.exe")
Set objShell = Nothing


End If

Now Im not the best VB Script person but the above code does work. There are lines I have commented out but I might need them at a later date so don't worry I have left them in. (It has been used from another post on another forum (which I can show but not sure if I can link to other sites in posts on here.) Can anyone tweek this so it included the timer and the ignoring if exists part (and also tidy up the code if required)

different scenarios

1) The user logs on on a new day and the script runs and then opens Notepad
2) The user logs on on the same day (after rebooting /logging off and on) and ignores the folder copy script and opens Notepad.

Many thanks

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>