Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > IDL > Re: Copy and re...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 188 of 236
Post > Topic >>

Re: Copy and rename list of files all with the same name

by jnettle1@[EMAIL PROTECTED] Jul 13, 2007 at 12:19 PM

On Jul 6, 6:35 am, cico <gg...@[EMAIL PROTECTED]
> wrote:
> Hi again guys, just to communicate that i resolved my issue, i'm
> re****ting the correct code
>
> ;GET LIST OF FILES
> Path = 'C:\source\'
> list = file_search(Path,'spectra.txt)
>
> ;READ IN ORDER THE FILE LIST
> for i=0, n_elements(list_orded)-1 do begin
>
> ;DEFINE OUTPUT DIRECTORY\FOLDER
> fdir='C:\destination\spectra'
>
> ;MAKING A PROGRESSIVE SUFFIX FOR THE OUTFILE
> suffix=strcompress(string(i),/remove_all)
> a=strlen(suffix)
> for k=0,2-a do suffix='0'+suffix
> out_fname=fdir+suffix +'.std'
>
> ;STARTS COPY PROCESS
> file_copy,list[i],out_fname
>
> ;PRINTS NUMBER FILE COPIED
> print,'spectrum copied=',[i]
>
> bye, cico


I'm not quite sure how you got your list of input files, but I think
you can do this without a loop, which will be faster.  In IDL
programming it's good practice to avoid loops wherever possible as
they are very slow in IDL.  Even when I know code written with a loop
won't take very long to execute, I still try to write vectorized
programs to keep me in the mindset of avoiding loops. So, assuming
your list of files is in the variable infiles:

i = indgen(n_elements(infiles))
ext = strtrim(string(i),2) + '.txt'
outfiles = file_basename(infiles, '.txt) + ext
file_copy, infiles, outfiles

I can't test this b/c i don't have your list of input filenames, but I
think it should work.  Or be very close to something that should
work :)

Jeff
 




 3 Posts in Topic:
Copy and rename list of files all with the same name
cico <ggs25@[EMAIL PRO  2007-07-05 04:45:25 
Re: Copy and rename list of files all with the same name
cico <ggs25@[EMAIL PRO  2007-07-06 03:35:57 
Re: Copy and rename list of files all with the same name
jnettle1@[EMAIL PROTECTED  2007-07-13 12:19:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 15:57:13 CST 2008.