Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: File Type Organizer..??  (Read 18052 times)

0 Members and 1 Guest are viewing this topic.

Dias de verano

  • Guest
Re: File Type Organizer..??
« Reply #30 on: February 03, 2009, 02:43:53 AM »
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!


gumbaz

    Topic Starter


    Intermediate

    Re: File Type Organizer..??
    « Reply #31 on: February 03, 2009, 03:51:18 AM »
    so how would you go about coding in a same name collision renaming function then all mighty Guru Master..??

    Dias de verano

    • Guest
    Re: File Type Organizer..??
    « Reply #32 on: February 03, 2009, 03:54:15 AM »
    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%
    « Last Edit: February 03, 2009, 04:33:39 AM by Dias de verano »

    gumbaz

      Topic Starter


      Intermediate

      Re: File Type Organizer..??
      « Reply #33 on: February 28, 2009, 08:01:24 AM »
      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..??

      Dias de verano

      • Guest
      Re: File Type Organizer..??
      « Reply #34 on: February 28, 2009, 08:27:18 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.
      « Last Edit: February 28, 2009, 08:39:06 AM by Dias de verano »

      gumbaz

        Topic Starter


        Intermediate

        Re: File Type Organizer..??
        « Reply #35 on: February 28, 2009, 09:22:35 AM »
        so how exactly would i use the !time! feature in my code then..??

        Dias de verano

        • Guest
        Re: File Type Organizer..??
        « Reply #36 on: February 28, 2009, 11:32:53 AM »
        Quote from: gumbaz
        so how exactly would i use the !time! feature in my code then..??

        The same way you used the %time% feature.