Detect a file is corrupted ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
anu
Posts: 3
Joined: 01 Jul 2022, 03:05

Detect a file is corrupted ?

Post by anu » 01 Jul 2022, 04:48

HI I am new to AHK.
I am developing script to scan files in the folder and list all the empty and corrupted files in to a csv.
Trying to find a way for AHK to return true or false for a function corruptedFile()

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Detect a file is corrupted ?

Post by BoBo » 01 Jul 2022, 05:37

Welcome to the AHK-Forum :thumbup:
Q: what's your indicator that a file is corrupt? Just its 0-byte filesize??

Code: Select all

MsgBox % func("C:\Dir\SubDir\*.*")

func(path) {
	Loop, Files,% path, R
		{	if (A_LoopFileSize=0)
			fIndex .= A_LoopFilePath ";"
		}
	FileAppend, % RTrim(fIndex,";"), corruptFiles.csv
	Return "Done!"
	}
Not tested. BTW, clicking a command within the code box will show its details. Happy scripting ;)

anu
Posts: 3
Joined: 01 Jul 2022, 03:05

Re: Detect a file is corrupted ?

Post by anu » 02 Jul 2022, 01:36

Hi Bobo,

Thank you very much for the quick reply.

Yes 0 byte file can be identified.
Q: what's your indicator that a file is corrupt? Just it's 0-byte filesize??
Actually I want to list any corrupted file. Is there a common indicator to identify corrupted files programmatically?
When considering media files, we get in to know that the file is corrupted only after opening the file. Is there a common way to capture the corrupted files without opening it?

Thank you very much

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Detect a file is corrupted ?

Post by BoBo » 02 Jul 2022, 02:25

When considering media files, we get in to know that the file is corrupted only after opening the file. Is there a common way to capture the corrupted files without opening it?
I'd assume that AHK’s :arrow: FileOpen()-function (and its return value output/A_LastError) can do the job?

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Detect a file is corrupted ?

Post by boiler » 02 Jul 2022, 05:11

It also depends on your definition of corrupted. It may be possible to open it and read all of its data but it doesn’t open in the intended application, such as an image file that is not able to be opened by an image viewer. In that definition of corrupt, there is almost no way programmatically to know whether a file is corrupt without having it opened by its application.

anu
Posts: 3
Joined: 01 Jul 2022, 03:05

Re: Detect a file is corrupted ?

Post by anu » 03 Jul 2022, 22:04

Thank you Bobo and Boiler,

I will try the opening, but when scanning and opening the files application GUI get stuck.
I will again try and let you know.

Thank you

Post Reply

Return to “Ask for Help (v1)”