Can anyone give me a code that will copy a file to the windows directory without giving me an ERROR! Thanx..
Printable View
Can anyone give me a code that will copy a file to the windows directory without giving me an ERROR! Thanx..
Ere you go.
Dim FileSysObject As Object
Set FileSysObject = CreateObject("Scripting.FileSystemObject")
FileSysObject.CopyFile "F:\Filename.txt", "c:\WINNT\"
Mad in Manchester.....
Code:Private Sub Command1_Click()
Dim SourcePath As String, DestPath As String
SourcePath = "c:\my documents\myFile.txt"
DestPath = "c:\Winnt\myFile.txt"
FileCopy SourcePath, DestPath
End Sub
HeSaidJoe's way is the proper way to do it. I am spending so much time working with ASP's and VBScript that I tend to use the File System Object alot. Still works though...
I want it to figure out the windows directory because for one, I change the windows directory name!
Code:'find the windows directory path
'usefull in shell commands if you know something
'is in the windows directory
'example..instead of shell c:\windows\notepad.ext
'you could use shell windir$ & /notepad.exe
'if windows was stored in E:/Windows then you wouldn't get an error
'if you used shell c:/windosw\notepad.exe, it couldn't be found '(error)
'
Option Explicit
Private Declare Function GetWindowsDirectory _
Lib "kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
'
Private Sub Form_Load()
'
Dim strFindWinDir$, WinDir$
'
WinDir$ = Space(144)
strFindWinDir$ = GetWindowsDirectory(WinDir$, 144)
WinDir$ = Trim(WinDir$)
'
MsgBox "The Windows Directory Path is: " & WinDir$
'
End Sub
Ianf
Your way is fine..the only diff is you need an extra dll when you export your application to others. If you are using the FSO for multiple instances of different situtations, then it's quite ok.
All ways that work are ok, they are just job specific for a certain set of circumstances.
My way
Dim WshShell As Object
Const pfad = "%windir%\"
Set WshShell = CreateObject ("WScript.Shell")
msgbox WshShell.ExpandEnvironmentStrings(pfad)
Your coding doesn't work because it doesn't let me type anyting after C:\WinMe
If I do this
MSGBOX GetWinDir & "\Lss.exe"
it will open a message boc with C:\WinMe
it doesn't show the rest of my message
nice code lanf! Thanx for the short and good code! I've been trying this for days!