Creating a right-click command to backup file

M

moonhkt

Hi All
I have Creating a right-click command to backup file try txt and then
xls file.

Try txt file ok.
Then try xls file, not ok, when right-click no option prompted ? Do
you know why ?

For txt file
REGEDIT4
[HKEY_CLASSES_ROOT\txtfile\shell\backupfile]
@="Backup Text File"


[HKEY_CLASSES_ROOT\txtfile\shell\backupfile\command]
@="cscript //b H:\Software\shell\xbcp.vbs "%1" "txt""


For excel file
REGEDIT4
[HKEY_CLASSES_ROOT\xlsfile\shell\backupfile]
@="Backup Excel File"


[HKEY_CLASSES_ROOT\xlsfile\shell\backupfile\command]
@="cscript //b H:\Software\shell\xbcp.vbs "%1" "xls""


Option Explicit

'~~ xbcp.vbs
'~~ 2010/02/24

dim objArgs, iArg
Dim fso,fso1
dim fn,newfn
Dim wdate
dim fncnt
dim fnprefix
dim fnext

Set objArgs = WScript.Arguments


for iArg = 0 To objArgs.count - 1
wscript.echo "Arguments=", objArgs(iArg)
if iArg = 0 then
fn = objArgs(iArg)
end if
if iArg = 1 then
fnext = objArgs(iArg)
end if
next

wscript.echo fn
wscript.echo fnext
fnprefix = mid(fn,1,instrrev(fn,fnext) - 2)
wscript.echo "fnprefix=" & fnprefix
Set fso = CreateObject("Scripting.FileSystemObject")

if fso.FileExists(fn) then
wDate = Year(Now) & Right("00" & Month(Now), 2) & Right("00" &
Day(Now), 2)
newfn = fnprefix & "_" & wdate & "." & fnext

set fso1 = CreateObject("Scripting.FileSystemObject")

fncnt = 0
if fso1.FileExists(newfn) then
while (fso1.FileExists(newfn))
fncnt = fncnt + 1
newfn = fnprefix & "_" & wdate & "_" & fncnt & "." & fnext
wend
end if

fso.copyfile fn, newfn

end if

wscript.echo ("DONE")


'~~ WScript.Sleep
1000
 
P

Paul Randall

You might want to crosspost this to microsoft.public.scripting.vbscript.

-Paul Randall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top