![]()
[<<]Message[>>] [<<]Author[>>] [<<]Subject[>>] [<<]Thread[>>]
Number : 9151 Date : 2004-11-06 Author : Jeremy Rector Subject : Re: File rename revisited Size(KB) : 4
Hi John, Thanks for the tweaking. This one is a little closer. It seem that some of my files are using the ` symbol in the filename (damn users), and I need to use a different delimiter. Out of the chute it works, just a little oddly. I think a little more tweaking on my end should fix it for good. I just need to find a valid character that my users aren't using to use as a delimiter and it should do the trick. I have been working on the file extension problem, nice solution I overlooked the filename.ext issue earlier, thanks for spotting and fixing that. (very elegent) I may actually be developing a handle on this now. :) Thanks Again! --- In xxcopy@yahoogroups.com, "John Zeman" wrote: > > --- In xxcopy@yahoogroups.com, "Jeremy Rector" > wrote: > > > > Hi Garry, > > > > Step 2 keeps failing, and I have gone over it with a fine tooth > comb. > > I stuck in break-points to troubleshoot, I get a file not found > error > > at step 2. The xxcopy portions of this script work exactly the way > > that they are supposed to. Any ideas? I am running under Win2k3. > > > > Thanks > > > > A couple areas you may be running into trouble with Garry's batch > file. In this line in Step 2: > > for /f "tokens=1-3,* delims=`" %%a in ('dir /b %tmp%') do ( > > Put " " around %tmp% (if your path contains spaces) so it becomes: > > for /f "tokens=1-3,* delims=`" %%a in ('dir /b "%tmp%"') do ( > > > > The other place you are likely having trouble is near the very end > where you see these two lines: > > ren "%tmp%\%fname%`%fdate%`%ftime%`%fpath%" > "%fname%-%fdate%-%ftime%`%fpath%" > > As Garry mentioned in his comment above it those two lines should be > combined on one line with a single space separating the two sections > enclosed in " " > > > Now that being said, I did a little more tweaking to Garry's batch > file so the dates and times are inserted between the destination file > names and the file extensions. My "source", "temp", > and "destination" directories are different than Garry's so you'll > need to change those to the correct ones for you. But otherwise you > might give the following a try (The success of this, like Garry's, > assumes you have a 5 level deep source i.e. something like: > > "C:\test folder\source\1105\1545\dir\". > > John > > > > @echo off > setlocal > set src=C:\test folder\source > > :: The above is the source path which has the yymmdd subdirs > :: If you want to pass this as a parameter, use: > :: set src=%~1 > if not exist "%src%" echo Source not found!&pause&goto :eof > > :: The next is the dest path where the renamed files will go > set dst=C:\test folder\destination > > :: The next is a temporary dir for the part renamed files > set tmp=C:\test folder\temp > > :: Clean out any files in the temporary path > rd /s/q %tmp% 2>nul > > :: Step 1. Gather files into the temp dir with the path > :: appended to the file name. Files end up with a name like > :: filename.ext`yyymmmdd`hh00`origpath > xxcopy "%src%\" "%tmp%\" /sr > > :: Step 2. Split each filename into its components of > :: filename, yyymmmdd, hh00, origpath then rename them to > :: filename-yyymmmdd-hh00`origpath > :: See FOR /? for an explanation of the FOR command > > for /f "tokens=1-3,* delims=`" %%a in ('dir /b "%tmp%"') do ( > set fname=%%~na > set fext=%%~xa > set fdate=%%b > set ftime=%%c > set fpath=%%d > call :rename > ) > > > :: Step 2A. Move Files to DIR directory > move "%tmp%\*.*" "%tmp%\%fpath%" > > :: Step 3. Rebuild the files using the original path > :: in the dest directory and remove after copy > :: Remove the /rcy if you want to view the renamed > :: intermediate files in the temp directory > xxcopy "%tmp%\%fpath%\" "%dst%\%fpath%\" /srr/rcy/y/pd0/ed > goto :eof > > :rename > :: This renames the files in the temp directory using the > :: extracted components of the gathered filename. > :: Note the the next line is wrapped. Everything before > :: the "goto :eof" should be on one line. > > :: NEXT IS ONE LONG LINE > ren "%tmp%\%fname%%fext%`%fdate%`%ftime%`%fpath%" "%fname%-%fdate%-% > ftime%%fext%" > > if not exist "%tmp%\%fpath%\." md "%tmp%\%fpath%" > goto :eof
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.