EZ said:
[snippedy-poo]
There is currently no intent to reprocess any of the target files; the
renamed files are part of an archive cleanup process. The archived
files will live in a network folder with very limited access; the file
rename process is more for easy identification and much less of a
security measure. None of the file names currently contain non-
alphanumeric characters. The date format of choice for the filename
append is yyyymmdd, and this date/time append is currently not present
in any of the filenames. But once any of the filenames bear this
append, it will serve as cue that it has already been processed.
I like the idea of the additional file extension processing for
protective measure.
So based on the feedback above, do you have any specific batch script
ideas that will perform this specific process as outlined?
Thanks again.
----- batch begins -------
[1]@echo off
[2]setlocal enabledelayedexpansion
[3]:: starting at Your Data Source, replicate tree to Your Data Destination
[4]set yds=c:\datasource
[5]set ydd=c:\datadest
[6]echo d|xcopy /t %yds% %ydd% >nul
[7]:: start processing at datasource
[8]pushd %yds%
[9]:: for extensions of interest, scan
[10]:: construct Your Destination Filename from filenames found
[11]::
[12]for %%e in (pdf txt) do for /r %%i in (*.%%e) do set ydf=%%~dpni&set
ydf=!ydf:%yds%=%ydd%!&call
rocess %%e "%%~ti" "%%~ni" "%%~fi"
[13]:: back to original dir
[14]popd
[15]goto :eof
[16]
[17]:: parameters are
[18]:: extent (1)
[19]:: quoted date-time(2)
[20]:: quoted-filename (3)
[21]:: quoted-full-sourcefilename(4)
[22]
rocess
[23]:: grab the last 8 characters of the filename as a "File Date"
[24]set yfd=%~3&set yfd=!yfd:~-8!
[25]:: if these are <20791232 then we have a date-suffixed name, so skip
[26]if %yfd% lss 20791232 echo %4 already suffixed
[27]if %yfd% lss 20791232 goto :eof
[28]:: so we need to copy this file. Examine the date part
[29]:: my date format is dd/mm/yy.
[30]set yfd=%~2
[31]set yfd=20%yfd:~6,2%%yfd:~3,2%%yfd:~0,2%
[32]:: if reformatted-date is >20791232, is 20th-century - subtract 1000000
[33]if %yfd% gtr 20791232 set /a yfd=%yfd% - 1000000
[34]ECHO copy %4 "%ydf%%yfd%.%1"
[35]
[36]goto :eof
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed
The ECHO keyword needs to be removed to activate the copy It is there as a
safety measure to show what the process WOULD do until
you have verified that it will do what you require
The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof
%varname% will be evaluated as the value of VARNAME at the time that the
line is PARSED. The ENABLEDELAYEDEXPANSION option to SETLOCAL causes
to be evaluated as the CURRENT value of VARNAME - that is, as modified by
the operation of the FOR
ye notes:
I wrote this using XP. It's possible that a few items may need to be
adjusted
lines starting with a double-colon are comments.
[4] It's important that the directory name inserted here is a case-match for
the actual name, otherwise the substitute in [12] may not take place
properly
[8] Not sure whether 2000 supports pushd with an argument. Might need
[8] pushd&cd %yds%
[12] I used txt and pdf for testing. The extensions you use are up to you.
Note that there may be some confusion with a file's short filename. For
instance, the file "something.HTML" will be detected by the for/r command as
matching "*.htm" because the files SHORT filename will be ...HTM
[24] Not sure whether the "-n" syntax works in 2K
[31] Since you've not specified the date format that you use, I've used the
format that I use which is dd/mm/yy. To adjust this, the formula can be
extracted from the documentation for set
SET /?
from the prompt (or anycommand /? from the prompt for (sometimes-cryptic)
help on anycommand)
- this may also aid in understanding the substitution used in [12]
FOR /? and alt.msdos.batch.nt may also be of aid in decoding some of the
more obscure aspects of this kind of processing.