• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

Creating a right-click command to backup file

M

moonhkt

Flightless Bird
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

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

-Paul Randall

"moonhkt" <moonhkt@gmail.com> wrote in message
news:f99ff169-8237-45a4-a012-a2ac90c7a156@q2g2000pre.googlegroups.com...
> 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
>
>
>
 
Top