1.

Solve : File Type Organizer..???

Answer»

I ran this deplorably ugly code on some test data and it seems that the variable !NUM! - which seems to be something gumbaz has devised for renaming a file in the event of a name collision - is being set to nothing (a blank) leading to a torrent of "ECHO is ON" messages and the variable being rendered literally rather than being expanded.

I mentioned about a week ago (on 26 Jan) that labels inside loops or other parenthetical structures are FROWNED UPON. I was ignored. The reason is that labels must be at the start of a line. The commands within the parentheses are really just one LONG line of multiple commands and the label ENDS up buried in the middle of that line. That code won't -ever- work.

Rather than repair this mess, I would call it a learning experience and start again, and this time I would:

Get the method and logic right and then write the code!

so how would you go about coding in a same name collision renaming function then all mighty Guru Master..??I would rename the incoming colliding file somehow. Maybe use the system clock which changes 100 times every second.

e.g.

Code: [Select]set timecode=%time%
set timecode=%timecode::=%
set timecode=%timecode:.=%
echo %timecode%Code: [Select]CD /D C:\FILES
set MEDIA=C:\[-MEDIA-]
setlocal enabledelayedexpansion
if not exist "%MEDIA%" MD "%MEDIA%"
for /f "delims=" %%F in ('DIR /ARASH /A-D /B /S') do (
if not exist "%MEDIA%\%%~xF" MD "%MEDIA%\%%~xF"
if not exist "%MEDIA%\%%~xF\%%~nxF" ATTRIB -H -S -A -R "%%F" & COPY "%%F" "%MEDIA%\%%~xF\%%~nxF" & DEL /F /Q "%%F" & ECHO MOVED "%%F" to "%MEDIA%\%%~xF\%%~nxF"
if exist "%MEDIA%\%%~xF\%%~nxF" ATTRIB -H -S -A -R "%%F" & COPY "%%F" "%MEDIA%\%%~xF\%%~nF(%TIME::=%)%%~xF" & DEL /F /Q "%%F" & ECHO MOVED "%%F" to "%MEDIA%\%%~xF\%%~nF(%TIME::=%)%%~xF"
)
Everything works ok in this new script except the (%TIME::=%) part at the end..
the time never changes when renaming the 2nd same named file collisions..
it just keeps the same time and if there are more than 2 same files the 3rd file gets deleted..??
whats causing the time to stay the same..??Quote from: gumbaz on February 28, 2009, 08:01:24 AM

Everything works ok in this new script except the (%TIME::=%) part at the end..
the time never changes when renaming the 2nd same named file collisions..
it just keeps the same time and if there are more than 2 same files the 3rd file gets deleted..??
whats causing the time to stay the same..??

Being in a loop causes %time% to stay the same. It would not happen with !time!. (Isn't that why you have enabled delayed expansion? - nothing else in that loop needs it that I can see.)

Also,

Code: [Select]"%MEDIA%\%%~xF\%%~nF(%TIME::=%)%%~xF" & DEL /F /Q "%%F" & ECHO MOVED "%%F" to "%MEDIA%\%%~xF\%%~nF(%TIME::=%)
the second TIME may not be the same as the first, since it measures to 1/100 second.
so how EXACTLY would i use the !time! feature in my code then..??Quote from: gumbaz
so how exactly would i use the !time! feature in my code then..??

The same way you used the %time% feature.


Discussion

No Comment Found