sumandevadiga

Copy File from 1 location to another by using VB script

12 posts in this topic

#1 ·  Posted (edited)

Hello 

Trying to add below code in my main script but this is not functioning can you advise what else i need to do?

 

	Dim fn As String
    Const myDir As String = "C:\AR\" '<- alter here
    Const newFolder As String = "C:\AR1\" '<- alter here
    fn = Dir(myDir & "AR_*.xlsm")
    Do While fn <> ""
        FileCopy myDir & fn, newFolder & Replace(fn, "AR", "AI")
        fn = Dir
    Loop

 

Edited by sumandevadiga
I did some error while pasting code

Share this post


Link to post
Share on other sites



#2 ·  Posted

So are you requesting help in regards to how to get an autoit script to work or a VB script?  If it is the latter, I am afraid you have the wrong forums...  However, if it is the former, please let me know, and I would be glad to help.

Share this post


Link to post
Share on other sites

#3 ·  Posted

In AutoIt it would be:

#include <FileConstants.au3>
Local $sSource = "C:\AR"
Local $sTarget = "C:\AR1"
DirCopy($sSource, $sTarget, $FC_OVERWRITE)

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

One way...line by line conversion from vbscript to autoit

#include <File.au3>
#include <FileConstants.au3>

;Dim fn As String
Local $fn
;Const myDir As String = "C:\AR\" '<- alter here
Const $myDir = "C:\AR\"
;Const newFolder As String = "C:\AR1\" '<- alter here
Const $newFolder = "C:\AR1\"
;fn = Dir(myDir & "AR_*.xlsm")
$fn = _FileListToArrayRec($myDir, "AR_*.xlsm", $FLTAR_FILES, $FLTAR_RECUR)
;Do While fn <> ""
For $sFile in $fn
;    FileCopy myDir & fn, newFolder & Replace(fn, "AR", "AI")
    FileCopy($myDir & $sFile, $newFolder & StringReplace($sFile, "AR", "AI"), $FC_OVERWRITE + $FC_CREATEPATH)
;    fn = Dir
;Loop
Next

 

Edited by spudw2k

Share this post


Link to post
Share on other sites

#6 ·  Posted

4 hours ago, MattHiggs said:

So are you requesting help in regards to how to get an autoit script to work or a VB script? 

Good point...sorry we jumped ahead

Share this post


Link to post
Share on other sites

#7 ·  Posted

Just now, spudw2k said:

Good point...sorry we jumped ahead

No worries man.  From the syntax that was posted, it looked more like Visual basic than Autoit, which is what prompted the question.  However, I don't have....well....any.....experience with Visual basic, so I wouldn't have been able to help if that were the case.  But at least he has the answer now if he needed help with autoit:P:P

Share this post


Link to post
Share on other sites

#8 ·  Posted

@sumandevadiga,

You need to put the filename to "true" to work with your code "objFSO.CopyFile" will not work with wildcards. Except you have it this way:

Dim fso As Object
    Dim FromPath As String
    Dim ToPath As String
    Dim objFSO, objFolder, strFile
    
  FromPath = "C:\AR\"
  ToPath = "C:\AR1\"
  
   If fso.FolderExists(FromPath) = False Then
     MsgBox "File doesn't exist. Not found!"
    Exit Sub
   End If
  
  For Each strFile In objFolder.Files
    If objFSO.GetExtensionName(strFile.Name) = "xlsm" Then
        objFSO.CopyFile strFile.Path, ToPath
    End If
  Next

Not tested, from my old VBscript. Hope you can get some idea and hope it helps.

If you want to use AutoIt, then you must follow Subz and spudw2k's posted above.

Share this post


Link to post
Share on other sites

#9 ·  Posted

Hello Kickstarter15,

Sorry for the delay reply, this is in VB script not Autoit, however i have tried your suggested code, this is not giving any output or result.

Dim fso As Object
    Dim FromPath As String
    Dim ToPath As String
    Dim objFSO, objFolder, strFile
    
  FromPath = "C:\AR\"
  ToPath = "C:\AR1\"
  
   If fso.FolderExists(FromPath) = False Then
     MsgBox "File doesn't exist. Not found!"
    Exit Sub
   End If
  
  For Each strFile In objFolder.Files
    If objFSO.GetExtensionName(strFile.Name) = "xlsm" Then
        objFSO.CopyFile strFile.Path, ToPath
    End If
  Next

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

this is autoit forum not vb forum, but if you want to copy files from 1loc to another loc you can do like this

 

 


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

#11 ·  Posted

@sumandevadiga,

Have you tried changing it? the logic is already in that script. Anyway, I have it this way:^_^

Set objFSO = CreateObject("Scripting.FileSystemObject")

    FromPath = "C:\AR\"
    ToPath = "C:\AR1\"

  Set objFolder = objFSO.GetFolder(FromPath)

  Set colFiles = objFolder.Files

  For Each objFile In colFiles
  strFileName = objFile.Name

      If objFSO.GetExtensionName(strFileName) = "xlsm" Then
        objFSO.CopyFile FromPath & objFile.Name, ToPath
      End If
  Next

NOTE: As what 232Showtime stated above, this is not a vbscript forum. So better to ask what does the forum is for.;)

Now, for AutoIt code this is how it was done:

#include <FileConstants.au3>
FromPath = "C:\AR\"
ToPath = "C:\AR1\"
FileCopy(FromPath & "*.xlsm", ToPath, $FC_OVERWRITE + $FC_CREATEPATH)

 

KS15

Share this post


Link to post
Share on other sites

#12 ·  Posted

Hello Kickstarter15,

Thank you very much for your support.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • ur
      By ur
      I am maintaining all the reusable code in a separate file as library.au3.
      In that file I have referenced some dependent files using fileinstall, so that they will be extracted when necessary.
       
      Problem is, if I use a function in the library.au3 in another script which doesn't require this dependent file, as I am including the whole file using include tag, it is embedding that file also.
      Is there any way to exclude that.
       
    • GTAVLover
      By GTAVLover
      I recently tried to use ControlClick method to send a mouse click command to a button in a application, but I noticed that it is not working when I give first parameter as a window handle (HWND). But, when I give class name or window title, it works fine. I used AutoItX3 and VBScript. 
      Following are the commands I tried in VBScript:
      Dim WINAPI: Set WINAPI = WScript.CreateObject("WinAPIWrapper.WINAPI") Dim AutoItX3: Set AutoItX3 = WScript.CreateObject("AutoItX3.Control") Dim WindowHandle: WindowHandle = WINAPI.WinAPI_FindWindow("my window title", "my window class") 'Window handle obtains fine by my wrapper function 'Above window handle is obtained as a hexadecimal string. (I.E. - 0x00000000) I tried it like: WScript.Echo CStr(AutoItX3.ControlClick(WindowHandle, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(CLng("&h" + Replace(WindowHandle, "0x", "")), "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(0x00000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK Only following commands work: WScript.Echo CStr(AutoItX3.ControlClick("[CLASS:my window class]", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE WScript.Echo CStr(AutoItX3.ControlClick("My window title", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE  
      If any of your suggestions don't work, I will have to write a wrapper function myself to send mouse click commands. I chosen AutoIt V3 because it is good specially when comes to send keystrokes to applications. Please tell me why this won't work when I give window handle as first parameter.
      Thanks in advance.
    • lattey
      By lattey
      i have a vbscript that called an autoit exe file and autoit exe file will return value to vbscript.
      vbscriptto call the exe and create array:
      Set objShell = CreateObject("WScript.Shell") objShell.Run ( "C:\Datalog\test.exe") Dim intCtr: intCtr=-1 Dim tempArr() Set UID = CreateObject("System.Collections.ArrayList") CurLot = "" For Each filelog in FileList LogFile = Split(filelog, "~")(1) Set otf = fso.OpenTextFile("C:\Datalog\" & LogFile, 1) intCtr=intCtr+1 sFile = Split(LogFile, "_") CurStep = sFile(4) Redim preserve tempArr(intCtr) tempArr(intCtr)=CurStep next autoit:
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <Array.au3> Global $Count = 10 Global $CheckBox[$Count] global $array1[1] $hGUI = GUICreate("Test", 500, 500) Global $array_Pstep[10] = ["P1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10"] $Spacing = 24 For $i = 0 To UBound($array_Pstep) - 1 $CheckBox[$i] = GUICtrlCreateCheckbox($array_Pstep[$i], 80, $Spacing + (20 * $i), 65, 17) Next $submit = GUICtrlCreateButton("submit",10, 300, 80, 30) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg case $submit _ArrayDisplay($array1) Case Else For $i = 0 To $Count - 1 If $CheckBox[$i] = $Msg Then MsgBox("", "Pressed", $i) _ArrayAdd($array1, $array_Pstep[$i]) ExitLoop EndIf Next EndSwitch WEnd i need to compare the array in vbscript and array return by autoit. but i dont know how to pass the value of array in autoit to vbscript. Please help.
    • Valnurat
      By Valnurat
      Is there any change that I can return a code for success or not success in my script?
      I have a script that look in a SQL db and write to the registry.
      I want to return some kind of a control, because I will call my script *.exe from VBScript.
      _Main() Func _Main() Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';', $sQUERY, $oRecordset, $aRecordsetArray, $aRecordset_inner Local $oConnection = _ADO_Connection_Create() _ADO_Connection_OpenConString($oConnection, $sConnectionString) If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE) $sQUERY = "Select Shipdate from " & $sTableName & " where ComputerName = '" & @ComputerName & "'" $oRecordset = _ADO_Execute($oConnection, $sQUERY) $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False) $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray) RegWrite("HKEY_CURRENT_USER\SOFTWARE\ComputerInfo", "Shipdate", "REG_SZ", $aRecordset_inner[0][0]) EndFunc  
    • messilm10
      By messilm10
      how do i get the crash report of any application and any running script?????