Desktop productivity for business analysts and programmers

Wrong file.

Reply
New Contributor
Posts: 3

Wrong file.

How to validate that a file exist without mistakes? Note the filexist function not say about a wrong file.

Super User
Posts: 3,866

Re: Wrong file.

Posted in reply to riarangogi

What is your definition of a file that is wrong or exists without mistakes?

New Contributor
Posts: 3

Re: Wrong file.

Posted in reply to riarangogi
Is when I can import a file.So, I want know how to detect the files we could import.
Super User
Posts: 23,342

Re: Wrong file.

Posted in reply to riarangogi

@riarangogi wrote:
Is when I can import a file.So, I want know how to detect the files we could import.


It depends, if you don’t have PCFILES you can’t open an XLSX file. Your criteria is still too broad. 

Vague question = vague answer. 

 

 

 

New Contributor
Posts: 3

Re: Wrong file.

[ Edited ]

What happens if the file exists but is damaged?

 

If file.txt is a  wrong file, then filexist function is true but I can't import it.

Highlighted
Super User
Posts: 9,925

Re: Wrong file.

Posted in reply to riarangogi

How would you detect that a .txt file is "wrong"? Once you know that, you can create code out of this algorithm. Note that you will have to read the file, and determine its state by the contents you read.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 370

Re: Wrong file.

Posted in reply to riarangogi

One thing we use a lot is a file header (the first line in the file) and a file footer (the last line in the file).

In the header number of rows are specified, also file creation date and name.

 

By reading the header we get information about the file which we then use to make an initial check if it's ok.

If so we stop.

 

If ok, we read the file and if we reach the footer we check the number of rows again.

 

//Fredrik

Ask a Question
Discussion stats
  • 6 replies
  • 203 views
  • 3 likes
  • 5 in conversation