ISUY
asked on
Need to create a script with [week day] variable
Hello, I need to create a script to copy files to a different path according to the day of the week.
for example, on monday, I need to copy c:\temp\1.txt to c:\backup\monday\
on tuesday I need to copy c:\temp\1.txt to c:\backup\tuesday\
so, is there any system enviroment variable so I use something like %week_day%
Of corse I need to do this for a more complex script, the example is just to get a picture of the idea.
Thanks a lot
for example, on monday, I need to copy c:\temp\1.txt to c:\backup\monday\
on tuesday I need to copy c:\temp\1.txt to c:\backup\tuesday\
so, is there any system enviroment variable so I use something like %week_day%
Of corse I need to do this for a more complex script, the example is just to get a picture of the idea.
Thanks a lot
WeekdayName function in VBS will return the name for the current day of the week. Here's more information: http://msdn.microsoft.com/en-us/library/00201has(v=vs.85).aspx
For example, if the directory names were as follows:
C:\backup\Sun
C:\backup\Mon
C:\backup\Tue
C:\backup\Wed
C:\backup\Thu
C:\backup\Fri
C:\backup\Sat
then the command (in the U.S.) would be simply:
copy "c:\temp\1.txt" "c:\backup\%date:~0,3%"
C:\backup\Sun
C:\backup\Mon
C:\backup\Tue
C:\backup\Wed
C:\backup\Thu
C:\backup\Fri
C:\backup\Sat
then the command (in the U.S.) would be simply:
copy "c:\temp\1.txt" "c:\backup\%date:~0,3%"
WScript.Echo Weekday(Now(),0)
1-Sunday
2-Monday
3-Tuesday
4-Wednesday
5-Thursday
6-Friday
7-Saturday
1-Sunday
2-Monday
3-Tuesday
4-Wednesday
5-Thursday
6-Friday
7-Saturday
If you post the result of this date command, showing your local date format, I will derive the macro for you, which you can then plug into the command in my previous post.
date/t
date/t
To elaborate on my first post. Here's the code that will print the day of the week for the current system date.
iDay = WeekDay( Date )
WSCript.Echo WeekdayName( iDay )
It will return full day names (i.e. Monday, Tuesday, etc.). It should not have any regional issues.
iDay = WeekDay( Date )
WSCript.Echo WeekdayName( iDay )
It will return full day names (i.e. Monday, Tuesday, etc.). It should not have any regional issues.
The following is based on the example you provided. It will copy data from C:\Temp to C:\Backup\<weekday>
(where <weekday> is whatever day it is>
(where <weekday> is whatever day it is>
Const OverWrite = True
strSource="C:\Temp\"
strDest="C:\Backup\" & WeekdayName(WeekDay(Now))
set objFSO = CreateObject ("Scripting.FileSystemObject")
objFSO.CopyFolder strSource, strDest, OverWrite
ASKER
the result of running the command
date/t
is:
16/02/2011
Thks
date/t
is:
16/02/2011
Thks
ASKER
I did try the example :
-------------------------- ---------- ---------- ---------- ----------
Const OverWrite = True
strSource="C:\Temp\"
strDest="C:\Backup\" & WeekdayName(WeekDay(Now))
set objFSO = CreateObject ("Scripting.FileSystemObje ct")
objFSO.CopyFolder strSource, strDest, OverWrite
-------------------------- ---------- ---------- ---------- ----------
but this will copy the contents of c:\temp\*.* to c:\backup\[week_day]\
how can I do to specify a File?, i did try the following:
-------------------------- ---------- ---------- ---------- ---------- ----------
Const OverWrite = True
strSource="C:\Temp\1.txt"
strDest="C:\Backup\" & WeekdayName(WeekDay(Now))
set objFSO = CreateObject ("Scripting.FileSystemObje ct")
objFSO.CopyFile strSource, strDest, OverWrite
-------------------------- ---------- ---------- ---------- ---------- ---------- ---
but this will copy the file to c:\backup\[week_day]
I need to copy the file without renaming to c:\backup\[week_day]\1.txt
Thks again.
--------------------------
Const OverWrite = True
strSource="C:\Temp\"
strDest="C:\Backup\" & WeekdayName(WeekDay(Now))
set objFSO = CreateObject ("Scripting.FileSystemObje
objFSO.CopyFolder strSource, strDest, OverWrite
--------------------------
but this will copy the contents of c:\temp\*.* to c:\backup\[week_day]\
how can I do to specify a File?, i did try the following:
--------------------------
Const OverWrite = True
strSource="C:\Temp\1.txt"
strDest="C:\Backup\" & WeekdayName(WeekDay(Now))
set objFSO = CreateObject ("Scripting.FileSystemObje
objFSO.CopyFile strSource, strDest, OverWrite
--------------------------
but this will copy the file to c:\backup\[week_day]
I need to copy the file without renaming to c:\backup\[week_day]\1.txt
Thks again.
Const OverWrite = True
strSource="C:\Temp\1.txt"
strDest="C:\Backup\" & WeekdayName(WeekDay(Now)) & "\1.txt"
set objFSO = CreateObject ("Scripting.FileSystemObje ct")
objFSO.CopyFile strSource, strDest, OverWrite
strSource="C:\Temp\1.txt"
strDest="C:\Backup\" & WeekdayName(WeekDay(Now)) & "\1.txt"
set objFSO = CreateObject ("Scripting.FileSystemObje
objFSO.CopyFile strSource, strDest, OverWrite
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok both solutions works good, time to raise the bet:
is there a way to check the file was correctly copied?, I mean compare source and deststination, and show a message "file succefully copyed to xxx" or "file not copied, check for errors"
thanks a LOT!
is there a way to check the file was correctly copied?, I mean compare source and deststination, and show a message "file succefully copyed to xxx" or "file not copied, check for errors"
thanks a LOT!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
date/t
In the U.S. (for example), the day-of-week can be determined with this macro:
@echo %date:~0,3%