Loading ...
Sorry, an error occurred while loading the content.

Re: [Chipmunk Basic Forum] Rename files

Expand Messages
  • Gary Morris
    Think of the filenames in the files as just strings. If they are not actually files in a directory, that s all they are really. If the one file has a filename
    Message 1 of 3 , Apr 13 5:52 AM
    View Source
    • 0 Attachment
      Think of the filenames in the files as just strings. If they are not
      actually files in a directory, that's all they are really. If the one file
      has a filename like '/onedir/twodirs/thefile.txt', use string functions
      to find the last '/' and remove what you want changed while in
      memory. Then, just replace that with a string function and write the
      name to the other file. You may chop it to '/onedir/twodirs', then
      append '/newfile.txt' or whatever and write it to the other file.


      That's all I can think of with the information given, and assuming I
      understand what you are after.

       
      G.


      ________________________________
      From: regisaddress <regisaddress@...>
      To: chipmunkbasicforum@yahoogroups.com
      Sent: Monday, April 9, 2012 1:28 PM
      Subject: [Chipmunk Basic Forum] Rename files


       
      Hey All,

      I want to make a program that will change the name of several files to different names. I have a list of the original file names "file.csv" and want to change then to the new file names contained in file "new.csv". What is the command to change a file name. I've been trying "name....as" but get a syntax error. Anyone have any advice? The program is below.

      -Kevin

      100 folder$ = "/Users/kevinmac/Desktop/KN207/file.csv"
      110 newnames$ = "/Users/kevinmac/Desktop/KN207/new.csv"
      200 dim fileold$(3000)
      300 dim filenew$(3000)
      400 open folder$ for data input as #1
      405 open newnames$ for data input as #2
      410 i = 0
      420 while not eof(1)
      430 i = i+1
      440 line input #1,fileold$(i)
      445 line input #2,filenew$(i)
      450 wend
      455 close #1 : close #2
      460 a$ = "/Users/kevinmac/Desktop/KN207/"
      470 for t = 1 to i
      480 old$ = a$+fileold$(t)
      490 new$ = a$+filenew$(t)
      500 print "renaming"
      510 print old$+" to "+new$
      515 name old$ as new$
      520 next t




      [Non-text portions of this message have been removed]
    • Gary
      After I read this a few times, I realized that maybe you ARE actually wanting to rename files. There is a command, save as or something
      Message 2 of 3 , Apr 18 12:03 PM
      View Source
      • 0 Attachment
        After I read this a few times, I realized that maybe you ARE actually wanting to rename files. There is a command, 'save <fname> as <newfname>' or something like that in a lot of basic's, I just can't get it to work with CB. If you are using a mac, there are some macfunctions that will do it, but I don't have one myself.

        --- In chipmunkbasicforum@yahoogroups.com, Gary Morris <gwmorris@...> wrote:
        >
        > Think of the filenames in the files as just strings. If they are not
        > actually files in a directory, that's all they are really. If the one file
        > has a filename like '/onedir/twodirs/thefile.txt', use string functions
        > to find the last '/' and remove what you want changed while in
        > memory. Then, just replace that with a string function and write the
        > name to the other file. You may chop it to '/onedir/twodirs', then
        > append '/newfile.txt' or whatever and write it to the other file.
        >
        >
        > That's all I can think of with the information given, and assuming I
        > understand what you are after.
        >
        >  
        > G.
        >
        >
        > ________________________________
        > From: regisaddress <regisaddress@...>
        > To: chipmunkbasicforum@yahoogroups.com
        > Sent: Monday, April 9, 2012 1:28 PM
        > Subject: [Chipmunk Basic Forum] Rename files
        >
        >
        >  
        > Hey All,
        >
        > I want to make a program that will change the name of several files to different names. I have a list of the original file names "file.csv" and want to change then to the new file names contained in file "new.csv". What is the command to change a file name. I've been trying "name....as" but get a syntax error. Anyone have any advice? The program is below.
        >
        > -Kevin
        >
        > 100 folder$ = "/Users/kevinmac/Desktop/KN207/file.csv"
        > 110 newnames$ = "/Users/kevinmac/Desktop/KN207/new.csv"
        > 200 dim fileold$(3000)
        > 300 dim filenew$(3000)
        > 400 open folder$ for data input as #1
        > 405 open newnames$ for data input as #2
        > 410 i = 0
        > 420 while not eof(1)
        > 430 i = i+1
        > 440 line input #1,fileold$(i)
        > 445 line input #2,filenew$(i)
        > 450 wend
        > 455 close #1 : close #2
        > 460 a$ = "/Users/kevinmac/Desktop/KN207/"
        > 470 for t = 1 to i
        > 480 old$ = a$+fileold$(t)
        > 490 new$ = a$+filenew$(t)
        > 500 print "renaming"
        > 510 print old$+" to "+new$
        > 515 name old$ as new$
        > 520 next t
        >
        >
        >
        >
        > [Non-text portions of this message have been removed]
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.