Results 1 to 5 of 5

Thread: How to copy the file from one location to another location using vbscript?

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Answers
    4

    How to copy the file from one location to another location using vbscript?

    Hi Friends,

    Please let me know how we can do the copy operation of a file using vbscript code?


    Regards,
    pradeep


  2. #2
    Expert Member
    Join Date
    Oct 2007
    Answers
    375

    Re: How to copy the file from one location to another location using vbscript?

    Hi,

    Try this -

    dim filesys
    set filesys=CreateObject("Scripting.FileSystemObject")
    If filesys.FileExists("c:\sourcefolder\anyfile.html") Then
    filesys.CopyFile "c:\sourcefolder\anyfile.html", "c:\destfolder\"
    End If


    The FileSys.CopyFile method should work. Just remember to pass the Source and Destination paths correctly.

    Cheers...


  3. #3
    Expert Member
    Join Date
    Sep 2007
    Answers
    110

    Re: How to copy the file from one location to another location using vbscript?

    Hi Pradeep,

    Try fhis,
    This is for Copying a file (located in desktop) into a folder (located into desktop)

    Set Shell = CreateObject("WScript.Shell")
    Set FSO = CreateObject("Scripting.FileSystemObject")
    SourceDesktopPath = Shell.SpecialFolders("Desktop") + "\rajaputra.txt" 'we can use either & or + to concotinate the strings
    DestinationDesktopPath = Shell.SpecialFolders("Desktop") + "\Destination\"
    FSO.CopyFile SourceDesktopPath, DestinationDesktopPath

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Arunsingh Rajaputra
    Software Test Engineer


  4. #4
    Junior Member
    Join Date
    Jan 2011
    Answers
    1

    Re: How to copy the file from one location to another location using vbscript?

    [QUOTE=bizzzzzare;23981]Hi,

    Thank you Bizzzz

    Here is a script which alos rename the file with concotinate date and time:


    Sub BackupExistFiles(FileName,ExcelPath)
    dim filesys
    set filesys=CreateObject("Scripting.FileSystemObject")
    If filesys.FileExists(ExcelPath & FileName) Then
    newName=Replace(Date,"/","_")&"_"&Replace(Time,":","-")
    filesys.CopyFile ExcelPath & FileName, ExcelPath & "tmp\"&NewName&"_"&FileName
    End If
    End Sub


  5. #5
    Junior Member
    Join Date
    May 2012
    Answers
    1

    Re: How to copy the file from one location to another location using vbscript?

    Quote Originally Posted by bizzzzzare View Post
    Hi,

    Try this -

    dim filesys
    set filesys=CreateObject("Scripting.FileSystemObject")
    If filesys.FileExists("c:\sourcefolder\anyfile.html") Then
    filesys.CopyFile "c:\sourcefolder\anyfile.html", "c:\destfolder\"
    End If


    The FileSys.CopyFile method should work. Just remember to pass the Source and Destination paths correctly.

    Cheers...
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    The above code is working perfectly working for me.
    But I have a scenario in which I need to copy some files from latest modified folder to destination folder. (may not know the folder name exactly) unless i go see it.
    Could you kindly help to fulfill this scenario.

    Thanks in advance.

    Kailash


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact