Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving a fiel from one location to another
#1
Solved: 10 Years, 9 Months, 1 Week ago
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
Reply
#2
Solved: 10 Years, 9 Months, 1 Week ago
' 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
Reply
#3
Solved: 10 Years, 9 Months, 1 Week ago
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
Reply
#4
Solved: 10 Years, 9 Months, 1 Week ago
what is the issue yuou are facing here
Reply
#5
Solved: 10 Years, 9 Months, 1 Week ago
I am facing like EXpected identifier
Reply
#6
Solved: 10 Years, 9 Months, 1 Week ago
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")
Reply
#7
Solved: 10 Years, 9 Months, 1 Week ago
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.
Reply
#8
Solved: 10 Years, 9 Months, 1 Week ago
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
Reply
#9
Solved: 10 Years, 9 Months, 1 Week ago
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.
Reply
#10
Solved: 10 Years, 9 Months, 1 Week ago
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to paste file location in QTP camillelola 0 1,343 08-09-2018, 10:54 AM
Last Post: camillelola
  Selecting file saved in a location excellentpawan 1 3,821 02-25-2014, 02:05 PM
Last Post: guin.anirban
  Copy file to network shared location sams001 0 2,965 04-03-2013, 02:10 AM
Last Post: sams001
MyBB Saving an excel file with the same name and same location after updating few columns pKrishna 1 4,741 01-04-2013, 04:40 PM
Last Post: Ankesh
  Moving QTP scripts from QC to a desktop PC adityasrinivasb 1 3,078 08-02-2011, 06:07 PM
Last Post: uma87

Forum Jump:


Users browsing this thread: 1 Guest(s)