Computing.Net > Forums > Disk Operating System > create directories and put files in

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

create directories and put files in

Reply to Message Icon

Name: ashok_k
Date: August 8, 2007 at 10:24:53 Pacific
OS: windows xp
CPU/Ram: 1.83ghz
Product: dell aspiration ds60
Comment:

I want to create directories and put files within it. for example I've files in c:\temp as follows.

Bookmark_CZOL446H2202_0101_0003_Regulatory.pdf
Bookmark_CZOL446H2202_0101_0008_Regulatory.pdf

Bookmark_CZOL446H2202_0302_0004_Regulatory.pdf
Bookmark_CZOL446H2202_0302_0005_Regulatory.pdf
Bookmark_CZOL446H2202_0302_0006_Regulatory.pdf

Bookmark_CZOL446H2202_0801_0003_Regulatory.pdf
Bookmark_CZOL446H2202_0801_0011_Regulatory.pdf

what I want to do is.. create directory 0101 from file Bookmark_CZOL446H2202_0101_0003_Regulatory.pdf and put this file with new name 0003.pdf in it.
so directory 0101 will have 0003.pdf & 0008.pdf files in it.

for file Bookmark_CZOL446H2202_0302_0004_Regulatory.pdf directory name should be 0302 and file name 0004.pdf. so directory 0302 will have 0004.pdf 0005.pdf & 0006.pdf

etc.



Sponsored Link
Ads by Google

Response Number 1
Name: alexanrs
Date: August 8, 2007 at 15:16:23 Pacific
Reply:

I don't think you can do that only with a BAT file. You'd probably have more luck trying to do something with C.
Anyway, in C a function to extract both names from the original name would be something like:

---------------
#include <dir.h>
#include <string.h>

int extract_names(const char orig[], char fldr[], char fname[])
{
char *substr, tmp[MAXPATH], ext[MAXEXT];
/* copies the original to a buffer so that
we can modify it */
strcpy(tmp,orig);
/* extracts the original extension */
fnsplit(tmp,NULL,NULL,NULL,ext);
/* skips the last '_' */
substr = strrchr(tmp,'_');
if (!substr) return 0;
/* finds the second last '_' */
substr = strrchr(tmp,'_');
if (!substr) return 0;
/* saves the file name */
strcpy(fname,substr+1);
/* adds the extension */
strcat(fname,ext);
*substr = '\0';
/* finds the third last '_' */
substr = strrchr(tmp,'_');
if (!substr) return 0;
/* saves the folder name */
strcpy(fldr,substr+1);
return 1;
}
---------------

This should extract the destination directory and the destination file name from the orginals, just create a "findfirst/findnext" loop, extract the names and do the copying.


0

Response Number 2
Name: Razor2.3
Date: August 20, 2007 at 20:41:03 Pacific
Reply:

It's doable with a Windows XP Command Script, but not from a DOS batch file.


0
Reply to Message Icon

Related Posts

See More


required UART jumpers. DOS support for Cardbus/U...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: create directories and put files in

Creating Directories question www.computing.net/answers/dos/creating-directories-question/13252.html

run batch file in non-current directory www.computing.net/answers/dos/run-batch-file-in-noncurrent-directory/11032.html

How can I remove files in DOS ? www.computing.net/answers/dos/how-can-i-remove-files-in-dos-/10052.html