×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to check if a file exists?

How to check if a file exists?

How to check if a file exists?

(OP)
Hi all,
could not find in the APDL documentation, if it is possible to somehow check if a file exists or not. Could then do branching based on this information. Any hints?

I'm using Ansys 9.0.

Thanks.

RE: How to check if a file exists?

You can use the code

CODE

/directory,names,file_name,file_extention,file_path
*get,numfiles,parm,names,dim,3

If numfiles is 0, then file is not existing.

But! I had some problems with the /directory comand. Sometimes for some files on some PC's I get some error like "Could not acces this file".

Regards,
Alex

RE: How to check if a file exists?

You may want to check out TCL/TK documentation/examples.

RE: How to check if a file exists?

Hi,

Mihaiupb's suggestion is great, and I think it won't work correctly only in the case that the directory and/or the filename doesn't respect Ansys' directives (which are greatly more stringent wrt Windows/Unix).

Regards

RE: How to check if a file exists?

Hi cbrn,

what kind of Ansys directives do you mean? I have never understood, why sometimes the /directory comand is not working...

Regards,
Alex

RE: How to check if a file exists?

Hi,
I don't remember all of them right now, but there is a limitation on the number of characters for the complete path+filename (248 char.s), other on the number of characters on the filename alone (32 bytes I seem to remember, but I may be wrong); if the path is the default one, then all available 248 char.s can be used for the filename. Extensions must be at most 8 bytes long, and Ansys can handle files with multiple extensions (such as myfile.v1.db) but in this case I don't know how the char counting behaves...
I also suspect there is some limitation in the number of sub-branches in a directory structure...
In order to be sure I never run into such problems, when the seed directory structure seems too complicated, I brutally duplicate it directly in "C:\" (shortest path possible!).
Blanks are allowed in path and filename, but then the path+filename must be enclosed in single quotes.

RE: How to check if a file exists?

Thanks cbrn. All this limitations are known to me. My ploblem is more complicated. Ansys refuses to work with some files. Till now I did not find any reasons for that. The /directory comand issues a warnig like "Could not acces this file". After that, the comand dose not work for all kind of files. To remediate this, I must restart Ansys!

Pretty strange, I must say...

Regards,
Alex

RE: How to check if a file exists?

Hi,
it's only an hypothesis: are the "inaccessible" files in a directory which doesn't have "SYSTEM" among the allowed read/write "users"?

Regards

RE: How to check if a file exists?

Thanks cbrn for the effort! You could have write. I think it should be the read/write thing... But I already checked the files an there are all "read only". So there should be no problem since the /directory command only reads. Also since all files are read only, there is no reason why some file can be read and some of them not...

Regards,
Alex
 

RE: How to check if a file exists?

I meant "You could have right", not "You could have write".

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources