Jump to content
sumandevadiga

Copy File from 1 location to another by using VB script

Recommended Posts

sumandevadiga

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
MattHiggs

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
Subz

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
spudw2k
spudw2k

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
spudw2k
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
MattHiggs
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
KickStarter15

@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.


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
sumandevadiga

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
232showtime

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
KickStarter15

@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


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
sumandevadiga

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

    • ufukreis1212
      By ufukreis1212
      Hello, I am new members. Help me please. I want vbs convert to au3 .
      This vbs code : 
      'deneme Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") strOSArch = GetObject("winmgmts:root\cimv2:Win32_OperatingSystem=@").OSArchitecture Set objNetwork = CreateObject("Wscript.Network") Set wshShell = CreateObject( "WScript.Shell" ) strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) Set oShell = WScript.CreateObject("WScript.Shell") proc_arch = oShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") Set oEnv = oShell.Environment("SYSTEM") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colMB = objWMIService.ExecQuery("Select * from Win32_BaseBoard") Set colCSes = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItemsx = objWMIService.ExecQuery( _ "SELECT * FROM Win32_VideoController",,48) '------------------------------------------------------------------- Set obj = GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory") i = 1 For Each obj2 In obj memTmp1 = obj2.capacity / 1024 / 1024 TotalRam = TotalRam + memTmp1 i = i +1 Next '-------------------------------------------------------------------- Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select Architecture from Win32_Processor") For Each objItem in colItems if objItem.Architecture = 0 then strArchitecture = "x86" end if if objItem.Architecture = 9 then strArchitecture = "x64" end if next '-------------------------------------------------------------------- strComputer = "." ' Local computer strMemory = "" i = 1 set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory") For Each objItem In colItems if strMemory <> "" then strMemory = strMemory & vbcrlf strMemory = strMemory & "Bank" & i & " : " & (objItem.Capacity /1024 /1024) & " Mb" i = i + 1 Next installedModules = i - 1 Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray") For Each objItem in colItems totalSlots = objItem.MemoryDevices Next '---------------------------------------------------------------------- Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" ) Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem" ) For Each objItem in colItems strComputerDomain = objItem.Domain Next for each System in SystemSet For Each objItem in colItemsx For Each objProcessor in colProcessors For Each bbType In colMB MbVendor = bbType.Manufacturer MbModel = bbType.Product MsgBox "İşletim Sistemi : " & System.Caption & vbNewLine & _ "İşletim Sistemi Versionu : " & + System.Version & vbNewLine & _ "Windows Mimari Yapısı: " & strOSArch & vbNewLine & _ "Kullanıcı isminiz: " & objNetwork.UserName & vbNewLine & _ "Bilgisayar ismi: " & strComputerName & vbNewLine & _ "Çalışma Grubu: " & strComputerDomain & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Anakart: " & MbVendor & " " & "[" & MbModel & "]" & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Grafik Kartı: " & objItem.Caption & vbNewLine & _ "Driver Version: " & objItem.DriverVersion & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "İşlemci Üreticisi: " & objProcessor.Manufacturer & vbNewLine & _ "İşlemci İsmi: " & objProcessor.Name & vbNewLine & _ "CPU Mimarisi: " & strArchitecture & vbNewLine & _ "İşlemci Çekirdek sayısı: " & oEnv("NUMBER_OF_PROCESSORS") & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Toplam RAM: " & TotalRam & " MB" & vbNewLine & _ "Toplam Slot: " & totalSlots & vbNewLine & _ "Boş Slot: " & (totalSlots - installedModules) & vbNewLine & _ "Ramlerin bulunduğu slotlar:" & vbcrlf & strMemory,0,"deneme" Next Next Next Next please help me , thanks.
    • jdegraff
      By jdegraff
      I'm trying to add a bit of functionality to the FastStone File Rename dialog. I can access every control that I need to except the one that contains the files to be renamed. If I do some exploring in a vbScript shell I get
      :c  = "TTntTreeView.UnicodeClass1"
      :?aut.ControlTreeView(win,"",c,"GetItemCount","","")
      5
      You can see that the treeview control reports having five items, which is the number displayed. If I manually select (mouse) item #3 I can see the result by
      :?aut.ControlTreeView(win,"",c,"GetSelected","1","")
      #3
      But I do not know how to get the text for the selected item. If "#3" is the item reference then I should be able to
      :?aut.ControlTreeView(win,"",c,"GetText","1","#3")
      or
      :?aut.ControlTreeView(win,"",c,"GetText","1","#3")
      if I go strictly by the help file, but it returns nothing.
      :?aut.ControlTreeView(win,"",c,"Exists","","3")
      1
      So it appears that item 3 exists, but
      :?aut.ControlTreeView(win,"",c,"GetText","","3")
      does not have any text???
      :?aut.ControlTreeView(win,"",c,"Exists","","9")
      1
      and it also appears item 9 exists (it does not)
      :?aut.ControlTreeView(win,"",c,"Select","","")
      1
      causes the first item to be selected, as does
      :?aut.ControlTreeView(win,"",c,"Select","","3")
      1
      Here is the output from the Window Info tool
      >>>> Window <<<<
      Title:  Batch Image Convert / Rename
      Class:  TBatchConvert
      Position:   501, 83
      Size:   760, 520
      Style:  0x16CD0000
      ExStyle:    0x00010100
      Handle: 0x0000000001950796
      >>>> Control <<<<
      Class:  TTntTreeView.UnicodeClass
      Instance:   1
      ClassnameNN:    TTntTreeView.UnicodeClass1
      Name:   
      Advanced (Class):   [CLASS:TTntTreeView.UnicodeClass; INSTANCE:1]
      ID: 37030040
      Text:   
      Position:   354, 79
      Size:   378, 188
      ControlClick Coords:    108, 86
      Style:  0x54010039
      ExStyle:    0x00000200
      Handle: 0x0000000002350898
      >>>> Mouse <<<<
      Position:   970, 279
      Cursor ID:  0
      Color:  0xE1E1E1
      >>>> StatusBar <<<<
      >>>> ToolsBar <<<<
      >>>> Visible Text <<<<
      Batch Rename
      ...
      D:\temp\picsave\
      Images + Videos (*.jpg;*.jpe;*.jpeg;*.bmp;*.gif;*.tif;*.tiff;*.cur;*.ico;*.png;*.pcx;*.jp2;*.j2k;*.tga;*.ppm;*.wmf;*.psd;*.crw;*.nef;*.cr2;*.orf;*.raf;*.dng;*.mrw;*.pef;*.srf;*.arw;*.rw2;*.x3f;*.sr2;*.srw;*.nrw;*.rwl;*.eps;*.avi;*.mpeg;*.mpg;*.wmv;*.mov;*.mp4;*.mts;*.mkv;*.m4v)
      Search and Replace
      Use Filename Template
      No Sort
      Clear
      Remove
      Add All
      Add
      Preview
      Close
      Rename
      No Change
      ?
       
       


    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • 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.
×