Ottar Posted February 23, 2024 Posted February 23, 2024 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
Ottar Posted February 23, 2024 Author Posted February 23, 2024 A small update. The script is able to copy files, but not directories...
ioa747 Posted February 23, 2024 Posted February 23, 2024 (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: to forum Edited February 23, 2024 by ioa747 I know that I know nothing
Ottar Posted February 23, 2024 Author Posted February 23, 2024 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now