Move a file using VL?

Discussion in 'AutoCAD' started by RaghuMN, Feb 15, 2005.

  1. RaghuMN

    RaghuMN Guest

    Hi all,

    Is there any VL-??? function (or any other function excluding SHELL function) to move a file from one directory to another?

    Thanks for any information,

    MNRaghu
     
    RaghuMN, Feb 15, 2005
    #1
  2. RaghuMN

    Jürg Menzi Guest

    Hi RaghuMN

    This should do what you want:
    Code:
    ;
    ; -- VxMoveFiles
    ; Moves the specified file(s).
    ; Copyright:
    ;   ©2002 MENZI ENGINEERING GmbH, Switzerland
    ; Arguments [Typ]:
    ;   Src = Source file(s) to move "C:\\Temp\\AllScrap.*" [STR]
    ;   Tar = Target directory/file "C:\\Scrap" [STR]
    ; Return [Typ]:
    ;   > T   VxMoveFiles succeed
    ;     Nil Error on move file(s)
    ; Notes:
    ;   - Requires ScrRun.dll (WinNT/Win9x/WinME only)
    ;   - If target file(s) exist, they be overwritten
    ;
    (defun VxMoveFiles (Src Tar / FilSys RetVal)
    (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
    RetVal (cond
    ((vl-catch-all-error-p
    (vl-catch-all-apply
    'vlax-invoke-method
    (list FilSys 'CopyFile Src Tar :vlax-true)
    )
    )
    )
    ((vl-catch-all-error-p
    (vl-catch-all-apply
    'vlax-invoke-method
    (list FilSys 'DeleteFile Src :vlax-true)
    )
    )
    )
    )
    )
    (vlax-release-object FilSys)
    (not RetVal)
    )
    
    Cheers
     
    Jürg Menzi, Feb 15, 2005
    #2
  3. RaghuMN

    Jürg Menzi Guest

    Repost my answer because I can't see it in the NNTP reader...

    Hi RaghuMN

    This should do what you want:
    Code:
    ;
    ; -- VxMoveFiles
    ; Moves the specified file(s).
    ; Copyright:
    ;   ©2002 MENZI ENGINEERING GmbH, Switzerland
    ; Arguments [Typ]:
    ;   Src = Source file(s) to move "C:\\Temp\\AllScrap.*" [STR]
    ;   Tar = Target directory/file "C:\\Scrap" [STR]
    ; Return [Typ]:
    ;   > T   VxMoveFiles succeed
    ;     Nil Error on move file(s)
    ; Notes:
    ;   - Requires ScrRun.dll (WinNT/Win9x/WinME only)
    ;   - If target file(s) exist, they be overwritten
    ;
    (defun VxMoveFiles (Src Tar / FilSys RetVal)
    (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
    RetVal (cond
    ((vl-catch-all-error-p
    (vl-catch-all-apply
    'vlax-invoke-method
    (list FilSys 'CopyFile Src Tar :vlax-true)
    )
    )
    )
    ((vl-catch-all-error-p
    (vl-catch-all-apply
    'vlax-invoke-method
    (list FilSys 'DeleteFile Src :vlax-true)
    )
    )
    )
    )
    )
    (vlax-release-object FilSys)
    (not RetVal)
    )
    
    Cheers
     
    Jürg Menzi, Feb 15, 2005
    #3
  4. RaghuMN

    BillZ Guest

    Not VL, But...

    (foreach n movelist ;specific filename list.
    (dos_exewait (strcat "cmd /c move path" n "Destination path") 3)
    )
    ;---;Move all list to same name..
    ;---;
    (dos_exewait (strcat "cmd /c move Path\\*.EXT Destination path\\") 3)



    Bill
     
    BillZ, Feb 15, 2005
    #4
  5. Yes, I just tried and this works:

    (vl-file-rename oldpath newpath)

    Just provide the full pathnames.
     
    Daniel J. Altamura, R.A., Feb 15, 2005
    #5
  6. RaghuMN

    RaghuMN Guest

    Juerg, BillZ and Daniel,

    Thanks for the replies.

    All the suggestions work.

    My observations:
    (vl-file rename .....) does not rename if the target file already exists. If needs to be overwritten, the old file needs to be deleted. In spite of this, this is the shortest solution.

    Juerg's code also takes care of replacing the target file if exists.

    I felt that using (dos_..) is a bit slower than the other 2 methods.

    Thanks again all the 3 gentlemen,

    MNRaghu
     
    RaghuMN, Feb 16, 2005
    #6
  7. RaghuMN

    BTO Guest

    little add : there is a MoveFile method with FileSystemObject

    (setq obj_wsh (vlax-create-object "Scripting.FileSystemObject"))
    (vlax-invoke-method obj_wsh 'MoveFile source destination )

    as written in WSH Help :

    source
    Required. The path to the file or files to be moved. The source argument
    string can contain wildcard characters in the last path component only.
    destination
    Required. The path where the file or files are to be moved. The destination
    argument can't contain wildcard characters.

    If destination is an existing file, an error occurs.


    thus, it's less effective than Jürg's method or vl-file-rename

    Bruno Toniutti
     
    BTO, Feb 16, 2005
    #7
  8. RaghuMN

    Jürg Menzi Guest

    Hi Bruno
    That's the point why I'm don't use the move method...;-)

    Cheers
     
    Jürg Menzi, Feb 16, 2005
    #8
  9. RaghuMN

    Jürg Menzi Guest

    Welcome...¦-)

    Cheers
     
    Jürg Menzi, Feb 16, 2005
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.