Discussion Locked

Move a file using VBS

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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 VBA a lot & some 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? That bit works fine, but I can't get it to actually move the file. :0(

Any suggestions?

Thanks

Matt

2 replies

by matt h

Got it! After hours of fiddling...

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, so this is really going to help!

Matt

by jackofalltech

Just out of curiosity, why are you doing this with VBS? Is it just a learning experience? The reason I ask is that this would be incredibly easier to do with either a 2-pane file manager or even the command-line.

Ralph

This discussion is closed to new replies.