Jump to content

Recommended Posts

Posted

Hi all,

 

Have done a search on the forums first but havent found anything relating to my question.

 

I have a lisp routine in which part of the program simply selects a file from a folder in my computer (using getfiled) and reads in the data points.

 

I was wondering if there was a way of selecting this file and copying it into another folder? (is there something like a copyfiled?)

 

So basically what i want to do is pick the original file, copy it into a different folder where another program (outside of Autocad) is automatically run which coverts the file into a different filetype, then lisp will read in that particular file and continue with the lisp routine.

 

Im pretty new to Autolisp. Hope that makes sense. Thanks for any help.

Posted

(vl-file-copy SOURCE DESTINATION)

example: (vl-file-copy (findfile "acad.cui") "c:\\acad.cui")

 

Hi all,

 

Have done a search on the forums first but havent found anything relating to my question.

 

I have a lisp routine in which part of the program simply selects a file from a folder in my computer (using getfiled) and reads in the data points.

 

I was wondering if there was a way of selecting this file and copying it into another folder? (is there something like a copyfiled?)

 

So basically what i want to do is pick the original file, copy it into a different folder where another program (outside of Autocad) is automatically run which coverts the file into a different filetype, then lisp will read in that particular file and continue with the lisp routine.

 

Im pretty new to Autolisp. Hope that makes sense. Thanks for any help.

Posted

Thanks alanjt, that works.

 

Is there a way of automatically saving my copied file with the same filename as the original?

 

What ive got is:

 

(SETQ sourcefile (getfiled "Select a source file" "n:/data/" "txt" )

(vl-file-copy sourcefile "n:/txt-convert/copiedfile.txt" )

 

so at the moment whatever the original file is that i select from the dialogue box it is saved as "copiedfile.txt". I would like to save the copied file with the original filename. So say i select "10455.txt" from the dialogue box, i want the copied filename to be the same. The original filename will almost always be a different number.

Posted

Some may say this is a little hack, but it's helpful nonetheless:

 

(vl-cmdf "shell" (strcat "ren " "\"" "C:\\file.type" "\" \"" "newfilename.type" "\""))

 

The "shell" command acts similarly to your Windows command prompt, in this case, you're sending the "rename" function to it. You just need to specify the file (with full directory) and the new file name. Carefully note the "\"" sequence repeated a few times; there's a reason for that. The file with directory and the file name MUST be in quotes, which means you need to use the control code for a quote.

 

You can also create and modify directories with the "shell" command. Open up your Windows command prompt and type "help" to see a list of commands you can use.

Posted

Like so:

(vl-file-copy SourceFile (strcat "c:\\" (vl-filename-base SourceFile) (vl-filename-extension SourceFile)))

 

Thanks alanjt, that works.

 

Is there a way of automatically saving my copied file with the same filename as the original?

 

What ive got is:

 

 

 

so at the moment whatever the original file is that i select from the dialogue box it is saved as "copiedfile.txt". I would like to save the copied file with the original filename. So say i select "10455.txt" from the dialogue box, i want the copied filename to be the same. The original filename will almost always be a different number.

Posted

Hi again.

 

New question, similar theme. :)

 

Now that the original file is copied into that folder, as i mentioned above an external program converts it from a .txt to a .dtc file (keeping the same 'filename base') and then deletes the .txt file from the folder leaving only the .dtc.

 

So i need my lisp routine to say "wait until .txt turns into .dtc" (which could vary from 5 seconds to 5 mins depending on file size), read the data fromt that file and then run through rest of program.

 

Im guessing some sort of while loop should do the trick, but it would be good to wait only the length of time it takes for the file to appear rather than just wait a specified length of time.

 

Any way of doing this? Thanks.

Posted

There is, actually.

 

You can search for the exact file you're looking for using (findfile ...) and stick that into an empty while loop. It would look something like this:

 

(while (not (findfile "filepath/filename.dtc")))

Basically, the loop will continue indefinitely until the file is found, at which point the loop will end and the rest of the program will run.

 

Just be careful with this, since the only way to break this loop is either for the file to appear or for you to hit "escape" to get out of it.

 

I'm sure this isn't the most elegant solution, but it's probably the quickest and easiest.

Posted

Thanks freerefill. It is actually the "filepath/filename.dtc" bit that i cant do. I cant actually specify the filename in the code because it wont be the same each time i run the program. The filename prefix will be a different number each time.

 

So i need some way of referring back to the 'vl-filename-base' bit. So it needs to be something like:

 

 while (not (findfile (strcat ("vl-filename-base' dtmfile) (vl-filename-extension "dtc"))) 

 

but obviously that wont work, i just dont know how to write it.

Posted

Take a look at your code, this is not a valid call:

("vl-filename-base' dtmfile)

With the use of VLide, these errors can easily be avoided.

 

Thanks freerefill. It is actually the "filepath/filename.dtc" bit that i cant do. I cant actually specify the filename in the code because it wont be the same each time i run the program. The filename prefix will be a different number each time.

 

So i need some way of referring back to the 'vl-filename-base' bit. So it needs to be something like:

 

 while (not (findfile (strcat ("vl-filename-base' dtmfile) (vl-filename-extension "dtc"))) 

but obviously that wont work, i just dont know how to write it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...