Jump to content

Recommended Posts

Posted

FIrst of all, I am new to AutoIt and scripting in general. I can read some code but not and expert by know means. What I am needing, hopefully is simple.

Scenario: I have two servers (old and new Listserv servers). On the old server I have several files that will need to be copied to the new server. The problem is the new server file structure is slightly different. Each file, on the old server, will need a Directory with the same name as the file on the new server. Example...(abc123.list (old server file) ---> ABC123\abc123.list on the new server. Hopefully there is an easy way to do this. If you notice, the directory name will need to also drop the extension.

Posted

Something like this:

$sSourceFilename = "abc123.list"
$sTargetDrive = "C:"
$aTargetDirectory = StringSplit($sSourceFilename, ".")
DirCreate($sTargetDrive & "" & $aTargetDirectory[1])
FileCopy($sSourceFilename, $sTargetDrive & "" & $aTargetDirectory[1] & "")
What's missing is some error checking code.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

I just threw this together:

To use it just save the script to the directory where the files are and run it.

#include <File.au3>

$Files = _FileListToArray(@ScriptDir, "*", 1)

For $I = 1 To $Files[0]

$Name = StringLeft($Files[$I], StringInStr($Files[$I], ".")-1)
If Not FileExists(@ScriptDir & "" & $Name) Then DirCreate(@ScriptDir & "" & $Name)

FileCopy(@ScriptDir & "" & $Files[$I], @ScriptDir & "" & $Name)

Next

MsgBox(0, "", "Done!")

It copies the file opposed to moving them just in-case something goes wrong and it also lacks recursion (but you didn't mention that so...)

Edited by Marlo
Click here for the best AutoIt help possible.Currently Working on: Autoit RAT
Posted

Glad to be of service :D

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

Here is my take on the output(s) you provided.

Local $sSourceFilePath = @ScriptDir & 'abc123.list'
Local $sDestinationFilePath = 'C:'

_FileCopyToFolder($sSourceFilePath, $sDestinationFilePath, 1 + 8) ; See FileCopy parameters.

Func _FileCopyToFolder($sSource, $sDestination, $iFlag = 0)
    Local $sFilePath = StringTrimLeft($sSource, StringInStr($sSource, '', 2, -1))
    $sDestination = StringRegExpReplace($sDestination, '[/]*$', '') ; Remove trailing slashes.
    $sDestination = $sDestination & '' & StringUpper(StringLeft($sFilePath, StringInStr($sFilePath, '.', 2, -1) - 1)) & '' & $sFilePath
    MsgBox(4096, '', $sDestination)
;~  Return FileCopy($sSource, $sDestination, $iFlag)
EndFunc   ;==>_FileCopyToFolder
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...