Count files - FileCopy - How? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Count files - FileCopy - How?

13 Apr 2021, 11:30

Hi!
First, all the desired files are counted (like this)

Code: Select all

Loop Files, % foldSelect1 "\*.pdf", R  ; Recurse into subfolders.
	countPDF += 1
Then, all the files is copied to another directory, and all file names is saved (like this)

Code: Select all

Loop Files, % foldSelect1 "\*.pdf", R  ; Recurse into subfolders.
{	FileCopy % A_LoopFileFullPath, % foldSelect2, 1
	countPDF1 += 1
	files .= A_LoopFileName "`n"
}
countPDF = 1498 (pcs)
countPDf1 = 1498 (pcs)

The csv-file contains 1498 filenames
but in the result directory (windows), it is only 1496 pcs (two files is missed)

If I only copy a few files (eg 15) I got the same value in Explorer as from the AHK- program.

I have tried ErrorLevel

Code: Select all

FileCopy % A_LoopFileFullPath, % foldSelect2, 1	; Skriv över befintilga filer
	If ErrorLevel
		MsgBox ,, Rad %A_LineNumber% -> %A_ScriptName%,	% countPDF1 "`n" A_LoopFileName
But no problems occurred!

Right now, I have no idea how to find the missed files :?
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Count files - FileCopy - How?

13 Apr 2021, 11:39

Perform a loop on the list of file names you wrote to your file, and check for the existence of each one using FileExist. For the ones that aren't found (presumably two), note them via MsgBox or writing their names to another file. That should identify which two of the 1498 were somehow missed.

Do you have any directories that have a .pdf extension? That could lead to the count being larger overall (by two directories) than the number of files.
User avatar
jasc2v8
Posts: 59
Joined: 10 Dec 2020, 12:24
Contact:

Re: Count files - FileCopy - How?

13 Apr 2021, 11:50

+1 for boiler's response.

I couldn't reproduce the problem on my system.
I did FileAppend, % files, myfiles.txt
myfiles.txt includes all the files.
You mention a CSV file, is there a CSV file used that I don't see in your code?
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Count files - FileCopy - How?

13 Apr 2021, 12:14

Code: Select all

... ; Recurse into subfolders.

Code: Select all

FileCopy % A_LoopFileFullPath, % foldSelect2, 1
Recurse into subfolders but copy all files into only one folder overwriting existing files silently?
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Count files - FileCopy - How?

13 Apr 2021, 12:18

Ah yes, @just me. I believe you nailed it.
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: Count files - FileCopy - How?

13 Apr 2021, 13:47

Thanks everyone!
Probably need to write a program that compares the csv file with the results directory. (as the @boiler mentioned)
At first I thought to save all filenames in an array, but now it became a csv file - right now it contains only the filename (not the path...)


All pdf-files are in many subdirectories (100pcs?) - along with a number of other files.
I think it can be difficult to reproduce the problem on another system, because the conditions are so specific.
Because the files are selected with .: Loop Files, % foldSelect1 "\*.pdf", R I think only current (pdf files) will be counted.
At first I thought that these files were locked by some program - but - No!

When does ErrorLevel occur?

(Will return when I have written the program)
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Count files - FileCopy - How?  Topic is solved

13 Apr 2021, 13:59

All you have to do is remove the 1 from the FileCopy options, because as @just me pointed out, that is causing it to silently overwrite the files with the same name. So just do that and check the value of ErrorLevel, and that will identify which files already exist when you try to copy another file with the same name over it.
Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: Count files - FileCopy - How?

14 Apr 2021, 04:19

Yes! :dance:
At first I did not understand what the difference would be. (the directory I copied to was empty from the beginning)

But now I see that two of the files were in two different directories (which I copied from). :)

Thanks everyone!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot], jomaweb, RussF and 301 guests