The magazine of the Melbourne PC User Group
Make Copies Of Paths and Files With Their Attributes Unchanged
Keith Phillips
|
|
The "ECHO XCOPIES" programs described here, copy complete paths, files and attributes to any drive. If a source file is deleted or corrupted, its "ECHO" can be copied back to the source directory using Windows Explorer because Windows Explorer also copies files with their attributes unchanged.
These programs are similar to the "MULTI MATCH Files" programs in PC Update, September
2001 [http://www.melbpc.org.au/pcupdate/2109/2109article11.htm]. They use the same C:\QB and C:\CLU directories and the same SOURCE.BAS program. Some of the code in ECHO.BAS is the same as in MULTI.BAS. In C:\CLU, double click the "RUN Qbasic" shortcut, open MULTI.BAS and highlight the block of common text.
Click
Edit | Copy | File | New | Edit | Paste| File| SaveAs
and name the new file ECHO.BAS. Type in the rest of the code and Save. Copy the code for the last subroutine from MULTI.BAS into ECHO.BAS and Save. In Notepad open MULTI.BAT, edit the 2nd and 3rd last lines and SaveAs
ECHO.BAT.
Make The Shortcut "MULTI MATCH Files"
In Windows Explorer, open the C:\Windows\SendTo directory. Right click the "MULTI MATCH Files" shortcut and in the pop-up menu select "Create Shortcut". Rename the new shortcut "ECHO XCOPIES" and edit its Program tab. See the XCOPIES Program tab image (Figure 1) below. Don't alter the Font or Screen tabs.
ECHO.BAS uses the Qbasic SHELL statement to run Xcopy.exe. In Windows 95 Xcopy.exe launches Xcopy32.exe. In Windows 98 98SE & Me, Xcopy.exe launches Xcopy32.mod. Xcopy.exe also passes the command line switches to the 32-bit program which copies the path, file and attributes. The switches are:
/D copy files only if the target is older than the source
/F displays full paths and names as folders are copied
/H also copies hidden and system folders
/K copies the source folder attributes to the target folder
/R overwrites read-only folders
/-Y prompt Yes/No/All before overwriting an existing target
|
Make The Target Directories
Source files can only be echoed to directories named XCOPIES. This prevents
files being accidentally echoed to the wrong target. You can change the target
directory name by altering XCOPIES in the 2nd line of ECHO.BAS but the
directory name must have no spaces and no more than eight letters. Make a
target directory on a floppy disk and test the program by echoing files to it.
When the program is OK, make target directories on other drives.
|

Figure 1. The XCOPIES Program Tab
|

Figure 2. Echo XCOPIES output
|
How To Echo Files
Select a source directory and edit the source list in the same way as for the "MULTI Match Files". Select one of the target directories and respond to the prompts. In the "ECHO XCOPIES" image
(Figure 2):
-
DIALICON.TXT is being echoed for the first time so there is no target file.
-
INSTALL.DOC has already been copied and is identical to its echo. The "/D" switch prevents the file from being copied.
-
The source README.TXT file is newer and is allowed by the "/D" switch to overwrite the older target README.TXT file and the "/-Y" switch displays the Yes/No/All prompt for you to confirm the overwrite.
-
The program ends with the message: "Match The Files That Have Been Xcopied Y/N". Press Y to run MULTI.BAS and compare the same list of source files that has just been used by ECHO.BAS.
Files echoed to drive A: (for example) from drive C: are in paths that begin A:\XCOPIES\C\... and files from D: are in paths A:\XCOPIES\D\... etc. The rest of each path is the same as the source. These paths shows exactly where the file was copied from so they can be restored, if necessary.
There may be error messages when echoing to removable disks:
-
"There is not enough space on the disk".
-
"The device is not ready" (there is no disk in the drive).
-
"The media is write protected" (the target directory exists on the disk but the disk is write protected so the file can't be
copied).
-
"Unable to create directory" (the disk is write protected so the path to the target directory can't be made and so the file can't be
copied).
| Figure 3. The batch
file ECHO.BAT (source can be downloaded
from here) |
@echo off
if exist C:\CLU\SOURCE goto use-source
rem ** SOURCE DOES NOT EXIST SO MAKE IT **
dir %1 /a-d>C:\CLU\DIR-LIST
C:\QB\QBASIC.EXE /RUN C:\CLU\SOURCE.BAS
rem ** SOURCE.BAS WILL MAKE C:\CLU\SOURCE **
goto end
:use-source
rem ** C:\CLU\SOURCE DOES EXIST SO USE IT **
dir %1 /a-d>C:\CLU\DIR-LIST
C:\QB\QBASIC.EXE /RUN C:\CLU\ECHO.BAS
rem ******** ECHO.BAS WILL XCOPY THE SOURCE FILES *********
:end |
| Figure 4. The code
listing for ECHO.BAS (source can be downloaded
from here) |
COLOR 17, 15: VIEW PRINT: CLS : COLOR , 10
target$ = "\XCOPIES\": length = LEN(target$)
PRINT SPC(31); "ECHO FILES & PATHS"; SPACE$(31)
OPEN "C:\CLU\DIR-LIST" FOR INPUT AS #1
FOR i = 1 TO 4: LINE INPUT #1, tmp$: NEXT i
CLOSE #1: path2$ = MID$(tmp$, 15) 'Path to target
IF LEN(path2$) > 3 THEN path2$ = path2$ + "\"
OPEN "C:\CLU\SOURCE" FOR INPUT AS #2: i = 0
DO: i = i + 1: LINE INPUT #2, tmp$ 'Foldername(s)
IF i = 3 THEN 'Line 3 is path to source
path1$ = tmp$: GOSUB VerifyPaths
ELSEIF tmp$ = "" THEN 'The line is blank
EXIT DO 'Get no file names below blank line
ELSEIF i > 3 AND LEFT$(tmp$, 1) <> " " THEN
GOSUB UseFileName 'File name is flush left
END IF 'Skip all file names preceded by space
LOOP UNTIL EOF(2)
CLOSE #2
PRINT SPC(9);"ECHO Finished! Match Files Have Been Xcopied Y/N"; SPC(9);
press$ = UCASE$(INPUT$(1))
IF press$ = "Y" THEN 'Match files using MULTI.BAS
cmd$ = "DIR " + file2$ + " /A-D >C:\CLU\DIR-LIST"
GOSUB ExecuteCommandLine: RUN "C:\CLU\MULTI.BAS"
ELSE
KILL "C:\CLU\SOURCE" 'Finished with this
END IF: SYSTEM 'Finished-Close screen
VerifyPaths: valid$ = "YES"
PRINT "Source="; path1$: PRINT "Target="; path2$
PRINT STRING$(80, 205)
IF UCASE$(RIGHT$(path1$, length)) = target$ THEN
valid$ = "NO": COLOR 14, 12
PRINT "ERROR Source MUST NOT end ..." + target$
END IF
IF UCASE$(RIGHT$(path2$, length)) <> target$ THEN
valid$ = "NO": COLOR 14, 12
PRINT "ERROR Target MUST end ..." + target$
END IF
IF valid$ = "NO" THEN
PRINT "PressAnyKey ": press$ = INPUT$(1)
CLOSE #2: KILL "C:\CLU\SOURCE": SYSTEM 'Close
END IF
RETURN
UseFileName: 'Uses only flush left files
filename$ = tmp$: GOSUB MakeFiles: c1 = CSRLIN
cmd$ = "DIR /A-D " + file1$ + " |FIND.EXE /I " + CHR$(34) + filename$ + CHR$(34)
GOSUB ExecuteCommandLine: c2 = CSRLIN
cmd$ = "DIR /A-D " + file3$ + " |FIND.EXE /I " + CHR$(34) + filename$ + CHR$(34)
GOSUB ExecuteCommandLine: c3 = CSRLIN
LOCATE c1, 1: PRINT "SizeDateTimeFile"
IF SCREEN(c2, 13) = 32 THEN
LOCATE c2, 1: PRINT "Replace If OLDER"
ELSE
LOCATE c2, 1: PRINT "New Path\File Can Be Made"
END IF: LOCATE c3, 1
PRINT "Do You Want To ECHO The Path\File Y/N ? ";
press$ = UCASE$(INPUT$(1))
IF press$ = "Y" THEN
PRINT "YES"
cmd$ = "C:\Windows\Command\Xcopy.exe " + file1$ + " " + file2$ + " /D/F/H/K/R/-Y"
GOSUB ExecuteCommandLine
ELSE
PRINT "NO"
END IF
IF CSRLIN >= 38 THEN 'Five Lines For Next File
FOR j = 1 TO 5: COLOR , 15: PRINT SPACE$(80)
NEXT j: LOCATE CSRLIN - 5, 1: COLOR , 10
END IF: PRINT STRING$(80, 205)
RETURN
MakeFiles:
file1$ = CHR$(34) + path1$ + filename$ + CHR$(34)
tp$ = path2$ + LEFT$(path1$, 1) + MID$(path1$, 3)
file2$ = CHR$(34) + tp$ + CHR$(34)
file3$ = CHR$(34) + tp$ + filename$ + CHR$(34)
RETURN
ExecuteCommandLine: 'Put cmd$ into a batch program
OPEN "C:\CLU\TEMP.BAT" FOR OUTPUT AS #1
PRINT #1, "@echo off": PRINT #1, cmd$
CLOSE #1: SHELL "C:\CLU\TEMP.BAT" 'Run batch prog
KILL "C:\CLU\TEMP.BAT" 'Delete batch program
RETURN |
Reprinted from the October 2001 issue of PC Update,
the magazine of Melbourne PC User Group, Australia
|