Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Please can you help

I want to create a script that copies a file from a list, renames the file and saves in a new location. I am using Auto Script see below script

VB
Opt("TrayIconDebug", 1)

$S_running = "find-copy-photos" ;name the script
If WinExists($S_running) Then
  MsgBox(0, "AutoIt", "The script to find and copy photos is already running")
  Exit
EndIf
AutoItWinSetTitle($S_running)

$FileName = FileOpenDialog("Select the file that contains the list of photos to find & copy", "C:\temp\", "Text File (*.txt)")
If @error Then Exit

$FileNameArray = StringSplit(FileRead($FileName), @CRLF, 1)

$PhotoFolder = FileSelectFolder("Select the top level folder that contains the photos.", "")
If @error Then Exit

$search = FileFindFirstFile($PhotoFolder & "\*.*")
If $search = -1 Then
  MsgBox(0, "Error", "No files/directories matched the search pattern")
  Exit
EndIf
While 1
  Local $file = FileFindNextFile($search)
  If @error Then ExitLoop
  
  For $i = 1 To $FileNameArray[0]
    If $file = $FileNameArray[$i] Then
      FileCopy($PhotoFolder & "\" & $file, @DesktopDir & "\output\", 8)
      $FileNameArray[$i] = ""
    EndIf
  Next
WEnd


For $i = 1 To $FileNameArray[0]
  If $FileNameArray[$i] <> "" Then
    InputBox("Error", "Could not find:", $FileNameArray[$i])
    If @error = 1 Then Exit
  EndIf
Next

Run("explorer.exe " & @DesktopDir & "\output\")
Posted
Updated 29-Jul-15 9:47am
v3
Comments
[no name] 16-Jul-15 7:03am    
And...? did you have a question this time? AutoIt has facilities built in for you to debug your script.
Member 11841550 16-Jul-15 7:15am    
Sorry I am a total novice at this, All I wanted to do was get a script that would copy files from a Text delimited file which has a list of file names and the renamed file name
copy them to another location
Sorry If I have not ask the question correctly

I really hope you can help.
[no name] 16-Jul-15 7:19am    
Okay... still, and? You have a script already and nothing you have said is a question.
Member 11841550 16-Jul-15 7:26am    
The Script that I have only creates a duplicate and dose not rename the file, how can I get the script to rename the file ?
[no name] 16-Jul-15 9:05am    
You have to actually give a new filename when you copy it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900