Web Development

General discussion


Move a file using VBS

By Matt H ·

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?



This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Move a file using VBS

by Matt H In reply to Move a file using VBS

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


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")


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!


Collapse -

Move a file using VBS

by JackOfAllTech In reply to Move a file using VBS

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.


Related Discussions

Related Forums