Micro Focus QTP (UFT) Forums
Moving a fiel from one location to another - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Moving a fiel from one location to another (/Thread-Moving-a-fiel-from-one-location-to-another)



Moving a fiel from one location to another - siri - 08-05-2008

Hi,
I need to move a file from one location to another
the below mentioned is the script
:
Move a file from one location to another.




-----------------------------------------------
Code:
'function: FileMove
'desc :    Moves a file from one location to another
' params :  strFile - full path to the source file
'           strTarget - the folder to move the file to
' returns : void
' ------------------------------------
Function FileMove(strFile, strTarget)

Dim objFS

' create a file system object
Set objFS = CreateObject("Scripting.FileSystemObject")

' check that the source file exists
If Not objFS.FileExists(strFile) Then

    ' fail if the source does not exist
    reporter.ReportEvent micFail, "Move File", "Unable to Move the File '"& strFile &"', It Does Not Exist"

Else

    ' create the destination folder if it doesn't already exist
    If Not objFS.FolderExists(strTarget) Then

        objFS.CreateFolder(strTarget)

    End If
    
    ' move the file
    objFS.MoveFile strFile, strTarget

End If

' destroy the object
Set objFS = Nothing

End Function 'FileMove

Here where i need to mention the Source fiel and target file
Source file :a
Target file :b


RE: Moving a fiel from one location to another - kishoreinchennai - 08-05-2008

' params : strFile - full path to the source file
' strTarget - the folder to move the file to

you need to call the function with these files....

Like :

FileMove(D:\ccc, D:\Target)


Regards
Kishore


RE: Moving a fiel from one location to another - siri - 08-06-2008

If i place tha also it is showing up an error like "expected identifier"

Code:
'function: FileMove
'desc : Moves a file from one location to another
' params : strFile - full path to the source file
' strTarget - the folder to move the file to
' returns : void
' ------------------------------------
Function FileMove("D:\ccc, D:\Target")

Dim objFS

' create a file system object
Set objFS = CreateObject("Scripting.FileSystemObject")

' check that the source file exists
If Not objFS.FileExists(strFile) Then

' fail if the source does not exist
reporter.ReportEvent micFail, "Move File", "Unable to Move the File '"& strFile &"', It Does Not Exist"

Else

' create the destination folder if it doesn't already exist
If Not objFS.FolderExists(strTarget) Then

objFS.CreateFolder(strTarget)

End If

' move the file
objFS.MoveFile strFile, strTarget

End If

' destroy the object
Set objFS = Nothing

End Function 'FileMove



RE: Moving a fiel from one location to another - surya_7mar - 08-06-2008

what is the issue yuou are facing here


RE: Moving a fiel from one location to another - siri - 08-06-2008

I am facing like EXpected identifier


RE: Moving a fiel from one location to another - surya_7mar - 08-06-2008

i am not sure if this is the mistake
Actual:
Function FileMove("D:\ccc, D:\Target")

Should be like
Function FileMove("D:\ccc", "D:\Target")


RE: Moving a fiel from one location to another - anemuday - 08-07-2008

Hi,

Since you are using Function and returning nothing to the function, you are getting that error.

If you use sub routine(sub) then you may not get the same error.

Here is the script i used to move a file from one location to another location. It worked fine for me.

Code:
Drivespec="D:\abc\psychology.doc"
DestFolderPath= "F:\abc\ijk"
MoveAFile Drivespec,DestFolderPath


sub MoveAFile(Drivespec,DestFolderPath)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.MoveFile Drivespec,DestFolderPath
    Set fso=nothing
End Sub

Regards,
Uday.


RE: Moving a fiel from one location to another - siri - 08-07-2008

Code:
Drivespec="D:\abc\psychology.doc"
DestFolderPath= "E:\abc\ijk"
MoveAFile Drivespec,DestFolderPath


sub MoveAFile(Drivespec,DestFolderPath)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile Drivespec,DestFolderPath
Set fso=nothing
End Sub




For the below script i am gettign an error as object not found


RE: Moving a fiel from one location to another - anemuday - 08-08-2008

Hi Siri,

How the same script is executed in your system.

Give a valid file path that exists in your system i.e give a valid file path in places of
Drivespec="D:\abc\psychology.doc" (valid file path)
DestFolderPath= "E:\abc\ijk"(valid folder path)

Regards,
Uday.


RE: Moving a fiel from one location to another - somisays - 08-09-2008

Dear Siri,
Use the following code...

Code:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.Movefile = "D:\abc\psychology.doc","E:\abc\ijk"


Make sure in d drive abc folder and psychology.doc exists
and In E drive abc and ijk folder exists.