Jump to content

Recommended Posts

Posted

Hi, I am trying to write a simple script to help me in my daily work. The script is supposed to:


1) open a file named Files.txt, which is a list of numbers
2) read it line by line
3) for each line, check if there is a directory with that name in the Files directory on the desktop 
4) if so, is to copy it to the desktop

The contents of the numbers.txt file are 1,2,3 in one column. The contents of the Files directory are directories named 1,2,3,4,5.

The result of executing the following script is a success message, but.... no directories appear on the desktop.

 

 

#include <File.au3>

; Define paths (change as needed)
Local $desktopDir = @DesktopDir
Local $filePath = $desktopDir & "\Files.txt"
Local $filesDir = $desktopDir & "\Files"

; Open the file for reading
Local $hFile = FileOpen($filePath, 0)
If $hFile = -1 Then
  MsgBox(0, "Error", "Cannot open file '" & $filePath & "'")
  Exit()
EndIf

; Read the file line by line
While 1
  ; Get the line
  $line = FileReadLine($hFile)
  If @error Then ExitLoop

  ; Check if the directory exists
  Local $directory = $filesDir & "\" & $line
  If FileExists($directory) Then
    ; Copy the directory to the desktop
    FileCopy($directory, $desktopDir & "\" & $line, 3)
  EndIf
WEnd

; Close the file
FileClose($hFile)

MsgBox(0, "Success", "Directories copied!")
 

Copy_1.au3

Posted (edited)

FileCopy ( "source", "dest" [, flag = 0] )

FileCopy($directory, $desktopDir & "\" & $line, 3)

 flag = 3 ? flag 3 not exist
make it $FC_OVERWRITE (1) + $FC_CREATEPATH (8) = 9

FileCopy($directory, $desktopDir & "\" & $line, 9)

 

Edit:

:welcome:   to forum

Edited by ioa747

I know that I know nothing

Posted

Thank you, it is better. Now it actually copies the selected directories from the Files directory. I just don't know why it converts them to files without extension. 

 

 

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
×
×
  • Create New...