copy a file to another file with a variable name - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

copy a file to another file with a variable name

delljohnbdelljohnb Posts: 81Member
I'm wanting to copy a complete text file (no data manipulation is needed and the file name is known) in it's entirety to another file that has a variable name. Both files will have the same extension on them (a CSV file as a matter of fact), but the pre-extension part of the file name to be copied to will be a variable (it will already have the .CVS extension as part of the variable value). I entend on using a string variable type for the destination file name. Any suggestions on how to do this? By the way, I need the code to generate the target file if it is not in the directory at the time that the copying is initiated, or if the file is present, then to everwrite it completely without any of the previous data being retained. The original file must be retained in its entirety.

Your assistance is greatly appreciated.

Delljohnb


Comments

  • delljohnbdelljohnb Posts: 81Member
    : I'm wanting to copy a complete text file (no data manipulation is needed and the file name is known) in it's entirety to another file that has a variable name. Both files will have the same extension on them (a CSV file as a matter of fact), but the pre-extension part of the file name to be copied to will be a variable (it will already have the .CVS extension as part of the variable value). I entend on using a string variable type for the destination file name. Any suggestions on how to do this? By the way, I need the code to generate the target file if it is not in the directory at the time that the copying is initiated, or if the file is present, then to everwrite it completely without any of the previous data being retained. The original file must be retained in its entirety.
    :
    : Your assistance is greatly appreciated.
    :
    : Delljohnb
    :
    :
    :
    Found the solution (pulled it out of thin air...LOL)!!!! I used a dummy variable and then used the assign function to transfer the name into the correct variable type, then used rewrite to set the file to write into. I then used a while not EOF loop to requentially read from one file and write to the other. ;-) It took 7 lines of code, but it worked. Does anyone know of a quick oneline solution? And yes...I thought about using Openwrite(), but I'm using TP 5.5 and that function is not supported. :-(
  • avvariavvari Posts: 1Member
    : : I'm wanting to copy a complete text file (no data manipulation is needed and the file name is known) in it's entirety to another file that has a variable name. Both files will have the same extension on them (a CSV file as a matter of fact), but the pre-extension part of the file name to be copied to will be a variable (it will already have the .CVS extension as part of the variable value). I entend on using a string variable type for the destination file name. Any suggestions on how to do this? By the way, I need the code to generate the target file if it is not in the directory at the time that the copying is initiated, or if the file is present, then to everwrite it completely without any of the previous data being retained. The original file must be retained in its entirety.
    : :
    : : Your assistance is greatly appreciated.
    : :
    : : Delljohnb
    : :
    : :
    : :
    : Found the solution (pulled it out of thin air...LOL)!!!! I used a
    : dummy variable and then used the assign function to transfer the
    : name into the correct variable type, then used rewrite to set the
    : file to write into. I then used a while not EOF loop to
    : requentially read from one file and write to the other. ;-)
    : It took 7 lines of code, but it worked. Does anyone know of a quick
    : oneline solution? And yes...I thought about using Openwrite(), but
    : I'm using TP 5.5 and that function is not supported. :-(
    :
    hi
    i want to do same type of copying of one fixed file name into another variable file name using !copy command from matlab environment. pls tell the procedure, how u did using 7 lines. i didnt understand what u mean
Sign In or Register to comment.