Considering there exists defects for Huffman coding to compress files, this paper presents a general algorithm to predict the vality of compressed files with variable-length coding. Through the pre-sentence of the prior estimate method of the average code length and the estimation method after file compressed, It implements a compressed file is no longer compressed. The algorithm includes character encoding and file encoding two stages, and it uses variable-length coding technique and compression rate information of the target file. First, it obtains the file code table from character probability statistics and the variable length encoding technique. Second, it uses the character probability and character code length to calculate the average code long. Finally, it determines whether the file is actually compressed according to the average code length of characters or the file compression ratio. Algorithm tests show: it can accurately pre-judge whether any type file can be compressed so that it only compresses the file that can be compressed.