Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.pdfBookmark_CZOL446H2202_0302_0004_Regulatory.pdf
Bookmark_CZOL446H2202_0302_0005_Regulatory.pdf
Bookmark_CZOL446H2202_0302_0006_Regulatory.pdfBookmark_CZOL446H2202_0801_0003_Regulatory.pdf
Bookmark_CZOL446H2202_0801_0011_Regulatory.pdfwhat 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.

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.

![]() |
required UART jumpers.
|
DOS support for Cardbus/U...
|

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