Subversion Repositories DevTools

Rev

Rev 2311 | Rev 2354 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2311 Rev 2313
Line 21... Line 21...
21
**                      The program will perform the following operations:
21
**                      The program will perform the following operations:
22
**                          (c) CopyFile
22
**                          (c) CopyFile
23
**                          (d) DeleteFile
23
**                          (d) DeleteFile
24
**                          (r) Remove Files (wildcard)
24
**                          (r) Remove Files (wildcard)
25
**                          (D) DeleteDir after deleting specified files (wildcard)
25
**                          (D) DeleteDir after deleting specified files (wildcard)
26
**                          (T) Delete Directory Tree
26
**                          (T) Delete Directory Trees
-
 
27
**                          (R) Delete Empty Directories
27
**
28
**
28
**                      Example Usage
29
**                      Example Usage
29
**
30
**
30
**                          JatsFileUtil c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
31
**                          JatsFileUtil c9 'copyFile'    aaa/bbb/ccc/dddd/file build_test.pl +w
31
**                          JatsFileUtil d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
32
**                          JatsFileUtil d9 'unCopyFile'  aaa/bbb/ccc/dddd/file
32
**                          JatsFileUtil r9 'deleteFile'  a1 b2 c3
33
**                          JatsFileUtil r9 'deleteFile'  a1 b2 c3
33
**                          JatsFileUtil D9 'DeleteFiles' src/WIN32P.OBJ *.err *.pch '*'
34
**                          JatsFileUtil D9 'DeleteFiles' src/WIN32P.OBJ *.err *.pch '*'
34
**                          JatsFileUtil T9 'DeleteTree'  interface
35
**                          JatsFileUtil T9 'DeleteTree'  interface
-
 
36
**                          JatsFileUtil R9 'RmDir'       build
35
**
37
**
36
**                      First two arguments are common to all
38
**                      First two arguments are common to all
37
**                          argv[1]     - Mode specifier, Debug specifier
39
**                          argv[1]     - Mode specifier, Debug specifier
38
**                          argv[2]     - Display Text
40
**                          argv[2]     - Display Text
39
**
41
**
Line 55... Line 57...
55
void DeleteDirTree( int argc, _TCHAR* argv[] );
57
void DeleteDirTree( int argc, _TCHAR* argv[] );
56
_TCHAR * makePath( _TCHAR *base, _TCHAR *path);
58
_TCHAR * makePath( _TCHAR *base, _TCHAR *path);
57
int DeleteOneFile (_TCHAR * dst );
59
int DeleteOneFile (_TCHAR * dst );
58
void DeleteOneDirectoryTree( _TCHAR* baseDir );
60
void DeleteOneDirectoryTree( _TCHAR* baseDir );
59
void copyOneFile( int argc, _TCHAR* argv[] );
61
void copyOneFile( int argc, _TCHAR* argv[] );
-
 
62
void RmDir( int argc, _TCHAR* argv[] );
60
 
63
 
61
/*
64
/*
62
**  Global
65
**  Global
63
*/
66
*/
64
char  verbose = 1;                          /* Debugging aid */
67
char  verbose = 1;                          /* Debugging aid */
Line 77... Line 80...
77
----------------------------------------------------------------------------*/
80
----------------------------------------------------------------------------*/
78
 
81
 
79
int _tmain(int argc, _TCHAR* argv[])
82
int _tmain(int argc, _TCHAR* argv[])
80
{
83
{
81
    /*
84
    /*
-
 
85
    **  User must provide some thing
-
 
86
    */
-
 
87
    if ( argc < 2 )
-
 
88
    {
-
 
89
        ErrorExit("Insufficient arguments",L"");
-
 
90
    }
-
 
91
 
-
 
92
    /*
82
    **  Examine the first argument
93
    **  Examine the first argument
83
    **  Must be a character string of
94
    **  Must be a character string of
84
    **      [0] - Mode : One character
95
    **      [0] - Mode : One character
85
    **      [1] - Verbose : 0 .. 9
96
    **      [1] - Verbose : 0 .. 9
86
    */
97
    */
Line 188... Line 199...
188
        **      argv[3]+  Base directory
199
        **      argv[3]+  Base directory
189
        */
200
        */
190
        case 'T':
201
        case 'T':
191
            DeleteDirTree(argc - 2, argv + 2 );
202
            DeleteDirTree(argc - 2, argv + 2 );
192
            break;
203
            break;
-
 
204
 
-
 
205
        /*
-
 
206
        **  Delete Empty Directories
-
 
207
        **      argv[2] - Text
-
 
208
        **      argv[3]+  Base directory
-
 
209
        */
-
 
210
        case 'R':
-
 
211
            RmDir(argc - 2, argv + 2 );
-
 
212
            break;
-
 
213
            
193
            
214
            
194
        default :
215
        default :
195
            ErrorExit("Unknown mode: ",argv[1]);
216
            ErrorExit("Unknown mode: ",argv[1]);
196
            break;
217
            break;
197
    }
218
    }
Line 585... Line 606...
585
 
606
 
586
        /*
607
        /*
587
        **  Iterate over all the files
608
        **  Iterate over all the files
588
        */
609
        */
589
        do {
610
        do {
590
            if ( verbose > 2 )
-
 
591
                fprintf(stderr, "Directory Entry:%ls,%ls\n", baseDir, FindFileData.cFileName );
-
 
592
 
-
 
593
            if ( _tcscmp( TEXT("."), FindFileData.cFileName ) == 0 )
611
            if ( _tcscmp( TEXT("."), FindFileData.cFileName ) == 0 )
594
                continue;
612
                continue;
595
 
613
 
596
            if ( _tcscmp( TEXT(".."), FindFileData.cFileName ) == 0 )
614
            if ( _tcscmp( TEXT(".."), FindFileData.cFileName ) == 0 )
597
                continue;
615
                continue;
598
 
616
 
-
 
617
            if ( verbose > 2 )
-
 
618
                fprintf(stderr, "Directory Entry:%ls,%ls\n", baseDir, FindFileData.cFileName );
-
 
619
 
599
            /*
620
            /*
600
            **  Create a full path to the file
621
            **  Create a full path to the file
601
            */
622
            */
602
            target = makePath( baseDir, FindFileData.cFileName);
623
            target = makePath( baseDir, FindFileData.cFileName);
603
            if ( FindFileData.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY)
624
            if ( FindFileData.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY)
Line 672... Line 693...
672
 
693
 
673
    return result;
694
    return result;
674
}
695
}
675
 
696
 
676
/*----------------------------------------------------------------------------
697
/*----------------------------------------------------------------------------
-
 
698
** FUNCTION           : RmDir
-
 
699
**
-
 
700
** DESCRIPTION        : Remove Empty directories
-
 
701
**
-
 
702
** INPUTS             : argc    - count of args
-
 
703
**                      argv    - list of files to delete
-
 
704
**                                [0]:  Text to display
-
 
705
**                                [1]+  Base directory
-
 
706
**
-
 
707
** RETURNS            : Will not return on error
-
 
708
**
-
 
709
----------------------------------------------------------------------------*/
-
 
710
 
-
 
711
 
-
 
712
void RmDir( int argc, _TCHAR* argv[] )
-
 
713
{
-
 
714
    int ii;
-
 
715
    _TCHAR *target;
-
 
716
 
-
 
717
    if ( argc < 2 )
-
 
718
        ErrorExit("Insufficient arguments for RmDir",L"");
-
 
719
        
-
 
720
    /*
-
 
721
    **  Display the user message
-
 
722
    **      Suppress display if the message is empty
-
 
723
    */
-
 
724
    if ( argv[0][0] )
-
 
725
    {
-
 
726
        fprintf(stderr, "%ls\n", argv[0]);
-
 
727
        fflush(stderr) ;
-
 
728
    }
-
 
729
 
-
 
730
    for ( ii = 1; ii < argc ; ii++)
-
 
731
    {
-
 
732
        target = makePath( argv[ii],NULL);
-
 
733
        if ( verbose > 2)
-
 
734
            fprintf(stderr, "RmDir: %ls\n", target);
-
 
735
        
-
 
736
        if ( ! RemoveDirectory (target) )
-
 
737
        {
-
 
738
            if ( verbose )
-
 
739
                fprintf(stderr, "Directory not deleted: %ls\n", argv[ii]);
-
 
740
        }
-
 
741
        free(target);
-
 
742
    }
-
 
743
}
-
 
744
 
-
 
745
/*----------------------------------------------------------------------------
677
** FUNCTION           : makePath
746
** FUNCTION           : makePath
678
**
747
**
679
** DESCRIPTION        : Creates a full file path for user
748
** DESCRIPTION        : Creates a full file path for user
680
**                      Join 2 components together
749
**                      Join 2 components together
681
**                      Convert relative path to ABS path with \\?\ from
750
**                      Convert relative path to ABS path with \\?\ from