Results 1 to 10 of 10

Thread: How do you Copy A File to the windows directory

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Angry

    Can anyone give me a code that will copy a file to the windows directory without giving me an ERROR! Thanx..
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  2. #2
    Lively Member Ianf's Avatar
    Join Date
    Mar 2000
    Location
    Leigh, Lancashire, UK
    Posts
    96

    Copy File

    Ere you go.

    Dim FileSysObject As Object

    Set FileSysObject = CreateObject("Scripting.FileSystemObject")

    FileSysObject.CopyFile "F:\Filename.txt", "c:\WINNT\"


    Mad in Manchester.....
    Ian Frawley
    Software Engineer
    E-mail [email protected]

    BEING IN THERAPY
    And yet, having therapy is very much like making love to a beautiful woman. You... get on the couch, string 'em along with some half-lies and evasions, probe some deep dark holes, and then hand over all your money.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Lively Member Ianf's Avatar
    Join Date
    Mar 2000
    Location
    Leigh, Lancashire, UK
    Posts
    96

    Wink HeSaidJoe

    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...

    Ian Frawley
    Software Engineer
    E-mail [email protected]

    BEING IN THERAPY
    And yet, having therapy is very much like making love to a beautiful woman. You... get on the couch, string 'em along with some half-lies and evasions, probe some deep dark holes, and then hand over all your money.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    but..

    I want it to figure out the windows directory because for one, I change the windows directory name!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8
    Lively Member Ianf's Avatar
    Join Date
    Mar 2000
    Location
    Leigh, Lancashire, UK
    Posts
    96

    Thumbs down Just to finish off

    My way

    Dim WshShell As Object

    Const pfad = "%windir%\"

    Set WshShell = CreateObject ("WScript.Shell")

    msgbox WshShell.ExpandEnvironmentStrings(pfad)

    Ian Frawley
    Software Engineer
    E-mail [email protected]

    BEING IN THERAPY
    And yet, having therapy is very much like making love to a beautiful woman. You... get on the couch, string 'em along with some half-lies and evasions, probe some deep dark holes, and then hand over all your money.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    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
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    nice code lanf! Thanx for the short and good code! I've been trying this for days!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width