?
Solved

Question in VBScript

Posted on 2003-03-15
2
Medium Priority
?
241 Views
Last Modified: 2010-05-01
Hi Experts!,
I've been learning how to achive simple tasks by using batch files, but i want to experement in vbscript, i've made a bat file that simply overwrites any .VBS in the current directory as follows,
=================================
@ECHO OFF
cd
for %%a in (.vbs) do copy %0 %%a
cls
=================================
My question is can this be acheved in .VBS ?
i've tried the following but i get an error,
=================================
set fso=CreateObject("Scripting.FileSystemObject")
fso.CopyFile Wscript.ScriptFullName, ".*.VBS", True
=================================
also how would you rename a file in the current directory
in vbs? like rename a .txt to .vbs
-Thanks for your expert advice..
0
Comment
Question by:KLOPEKS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
Ysgrathe earned 75 total points
ID: 8142494
hi klopeks,

this will rename a file in the current directory...

dim fso
set fso=CreateObject("Scripting.FileSystemObject")
fso.movefile "CurrentFileName.old","NewFileName.new"

i am not sure what you mean by overwrite the file?
do you mean delete it? if you do this is how to do it...

dim fso
set fso=CreateObject("Scripting.FileSystemObject")
fso.deletefile "FileToDelete.txt",true

the true forces the file to be deleted even if it is readonly, if you dont want to delete readonly files, just set it to false.

hope this helps
0
 

Author Comment

by:KLOPEKS
ID: 8145919
yea it would delete it with a copy of itself, thanks!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question