Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move an existing file with a VS Script

Status
Not open for further replies.

linmatt

Technical User
May 22, 2002
50
GB
Hi

I'm trying hard to get to grips with VBS and getting frustrated. Need to get a good beginners book - any suggestions? (I use Excel VBA a lot & a little VB 6). I simply want to be able to move a small text file from one folder in a mapped drive "n:\out" to it's parent "n:\", after typing the file name into an input box. Simple, yes? The inpout box bit works fine, but I can't get it to actually move the file. :0(

Any suggestions?

Thanks

Matt
 
Got it!

Here is the final code for anyone else who may want it. It's probably not the best but - hey - it works! The main part is a sub cos I want to expand it in the future. This is just the begining.......

'==================================================
' Move EXxxx file for re-export MH 14/07/2003
'==================================================

Move

Sub Move()

dim exFileName, fso

set fso = createobject("scripting.filesystemobject")
exFileName = inputbox("File name","Move file")

If fso.FileExists ("N:\out\" & exFileName) Then

'Move the file to parent directory for export

fso.MoveFile "n:\out\" & exFileName,"n:\" & exFileName

msgbox("File has been moved")

else

msgbox("File does not exist")

exit sub

End If

fso = nothing
exFileName = nothing

End Sub

It moves a 2k text file from a folder to the parent folder, but there are 15,000 of them, and searching isn't hard but is time consuming. This does it in a fraction that time. I do this a lot sometimes, eso this is really going to help!

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top