Subscribe Bookmark RSS Feed

How to change file names?

natalie_

Community Trekker

Joined:

Jan 6, 2016

Hi everyone,

Earlier I asked about how to extract files and it is working great!  Now I want to use these files, but the files are saved with ".pda-iv" (the file are coming from a parameter analyzer B1506).  In my script to open the file (ronFolder = Open(directory || deviceName || "\" || "RDS-ID.pda-iv");), I get an "Error with File: Path is Invalid" error.

Is there a way to change the name of the file?  For example, instead of RDS-ID.pda-iv, have it as RDS-ID.text.

Here is my code from how I extracted files:

/* 1) This script assumes all files within zipped files are text files.

   2) Make sure only zipped files are in the directory (ie., only B1506A data sheet zipped files)*/

directory = Pick Directory ();  //Choose directory where zipped folders are

filesInDirectory = Files In Directory(directory); //get list of files in directory

nFiles = N Items(filesInDirectory);  //get number of zip files in directory

For(i=1, i<=nFiles, i++,

           

      fileName = filesInDirectory[i];  //select ith file in list of

     

      /********Determine Device Name***********/

      pos = Contains(fileName, "_");      ///(example file name: GS66508T 65R6 #1_7-19-2016_11-04-28_AM.pda-ds)

      deviceName = left(fileName,pos-1); 

      /****************************************/

     

      /*******Create subdirectory for extracted files. 

            Make sure it is in a directory separate from all the zipped files*****/

      subDir = "C:\R&D Data\TSMC\E-HEMT\GS66508T\GS66508T 65R6 extractions\" || deviceName || "\";

      Create Directory(subDir);    

      /*************************************************************************/  

     

     

      za = Open(directory || fileName, zip); //Open zipped folder

      dirlist = za << dir;                            //Get list of files in zipped folder

      nZippedFiles = N Items(dirlist);          //get number of files in dirlist

     

      /*Step through dirlist and save each text file into the new sub directory*/

      for(k=1, k<=nZippedFiles , k++,          

            If(Right(dirlist[k],4) == ".txt",

                  text = za << read (dirlist[k]);

                  Save Text File(subDir || dirlist[k], text),);

     

      );

      /************************************************************************/

     

);

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Got it!  It was really simple.  I am not sure why I got hung up on the Save Text File function.

/* 1) This script assumes all files within zipped files are text files.

   2) Make sure only zipped files are in the directory (ie., only B1506A data sheet zipped files)*/

directory = Pick Directory ();  //Choose directory where zipped folders are

filesInDirectory = Files In Directory(directory); //get list of files in directory

nFiles = N Items(filesInDirectory);  //get number of zip files in directory

For(i=1, i<=nFiles, i++,

  fileName = filesInDirectory;  //select ith file in list of

  /********Determine Device Name***********/

  pos = Contains(fileName, "_"); ///(example file name: GS66508T 65R6 #1_7-19-2016_11-04-28_AM.pda-ds)

  deviceName = left(fileName,pos-1);

  /****************************************/

  /*******Create subdirectory for extracted files. 

  Make sure it is in a directory separate from all the zipped files*****/

  subDir = "C:\R&D Data\TSMC\E-HEMT\GS66508T\GS66508T 65RG new extensions\" || deviceName || "\";

  Create Directory(subDir);

  /*************************************************************************/

  za = Open(directory || fileName, zip);  //Open zipped folder

  dirlist = za << dir; //Get list of files in zipped folder

  nZippedFiles = N Items(dirlist); //get number of files in dirlist

  /*Step through dirlist and save each text file into the new sub directory*/

  for(k=1, k<=nZippedFiles , k++,

  If(Right(dirlist,4) == ".txt",

  text = za << read (dirlist);

  fileNameZip = dirlist;

  pos = Contains(fileNameZip, ".");

  newFileName = Left(fileNameZip, pos-1);

  newFileName = newFileName || ".txt";

  Save Text File(subDir || newFileName, text),);

  );

  /************************************************************************/

);

2 REPLIES
natalie_

Community Trekker

Joined:

Jan 6, 2016

Strange, I can open them manually but I can't get the script to work?

Solution

Got it!  It was really simple.  I am not sure why I got hung up on the Save Text File function.

/* 1) This script assumes all files within zipped files are text files.

   2) Make sure only zipped files are in the directory (ie., only B1506A data sheet zipped files)*/

directory = Pick Directory ();  //Choose directory where zipped folders are

filesInDirectory = Files In Directory(directory); //get list of files in directory

nFiles = N Items(filesInDirectory);  //get number of zip files in directory

For(i=1, i<=nFiles, i++,

  fileName = filesInDirectory;  //select ith file in list of

  /********Determine Device Name***********/

  pos = Contains(fileName, "_"); ///(example file name: GS66508T 65R6 #1_7-19-2016_11-04-28_AM.pda-ds)

  deviceName = left(fileName,pos-1);

  /****************************************/

  /*******Create subdirectory for extracted files. 

  Make sure it is in a directory separate from all the zipped files*****/

  subDir = "C:\R&D Data\TSMC\E-HEMT\GS66508T\GS66508T 65RG new extensions\" || deviceName || "\";

  Create Directory(subDir);

  /*************************************************************************/

  za = Open(directory || fileName, zip);  //Open zipped folder

  dirlist = za << dir; //Get list of files in zipped folder

  nZippedFiles = N Items(dirlist); //get number of files in dirlist

  /*Step through dirlist and save each text file into the new sub directory*/

  for(k=1, k<=nZippedFiles , k++,

  If(Right(dirlist,4) == ".txt",

  text = za << read (dirlist);

  fileNameZip = dirlist;

  pos = Contains(fileNameZip, ".");

  newFileName = Left(fileNameZip, pos-1);

  newFileName = newFileName || ".txt";

  Save Text File(subDir || newFileName, text),);

  );

  /************************************************************************/

);