opening of files in a specified directory

  • Follow


Hi,

I've written (thanks also to this newsgroup!) the following script
for opening multiple files, e.g.:
test_0001
test_0002
....

for i=1:N
   xx=sprintf('%4d',i);
   tag=strrep(xx,' ','0');
   all=['test_',tag,'.txt'];
   fid = fopen(all, 'at');
end

this allows to create all the files in the /work matlab subfolder.

I need to create these files in a subdirectory such as
/work/test

How can I manage it?

Thanks for helping
0
Reply mail.plutus (24) 5/27/2005 7:35:16 AM

Bart wrote:
>
>
> Hi,
>
> I've written (thanks also to this newsgroup!) the following script
> for opening multiple files, e.g.:
> test_0001
> test_0002
> ...
>
> for i=1:N
> xx=sprintf('%4d',i);
> tag=strrep(xx,' ','0');
> all=['test_',tag,'.txt'];
> fid = fopen(all, 'at');
> end
>
> this allows to create all the files in the /work matlab subfolder.
>
> I need to create these files in a subdirectory such as
> /work/test
>
> How can I manage it?
>
> Thanks for helping

take a look at FULLFILE
myfullfile = fullfile(mydir, myfilename) ;

btw, avoid using function names (ALL) as variable names ...

Jos
0
Reply Jos 5/27/2005 8:14:55 AM


Hi Bart,

I guess your files are created in a folder something like
C:\Program\MATLAB7\work. Before you create the files you must change
the current directory to C:\Program\MATLAB7\work\test. It can be done
like this

filePath='C:\Program\MATLAB7\work\test'
cd(filePath)

Commands such as mkdir, dir, fileparts, mfilename, path, pwd, what,
dir, fileattrib, filebrowser, fileparts, ls, mfilename, movefile,
rmdir and so on may also be useful when handling files.

I hope this helps.

Markus

Bart wrote:
>
>
> Hi,
>
> I've written (thanks also to this newsgroup!) the following script
> for opening multiple files, e.g.:
> test_0001
> test_0002
> ...
>

>
> this allows to create all the files in the /work matlab subfolder.
>
> I need to create these files in a subdirectory such as
> /work/test
>
> How can I manage it?
>
> Thanks for helping
0
Reply maslit98 (5) 5/27/2005 8:17:30 AM

Markus Lindkvist wrote:
>
>

>
> filePath='C:\Program\MATLAB7\work\test'
> cd(filePath)
>

It works!!

Thanks alot for helping ;)
0
Reply mail.plutus (24) 5/27/2005 8:37:14 AM

3 Replies
16 Views

(page loaded in 0.069 seconds)

Similiar Articles:













7/22/2012 2:34:15 PM


Reply: