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

Author Topic: DOS Batch  (Read 16410 times)

0 Members and 1 Guest are viewing this topic.

Bones92



    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: DOS Batch
« Reply #15 on: January 27, 2008, 01:39:33 AM »
Sorry if I seem annoying or anything... but I'm sure that

Code: [Select]
Set newname=%RANDOM%.%RANDOM%
ren %1 %newname%
Del %newname%
pause
exit


works... it just worked for me.

I ran it from cmd.exe, if that makes a difference...


Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: DOS Batch
« Reply #16 on: January 27, 2008, 05:53:09 AM »
c:\docume~1\user>Set newname=725.23907
c:\docume~1\user>ren "C:\docume~!\user\desktop\test.txt 725.23907
c:\docume~1\user>DEL C:\docume~1\user\desktop\725.23907
The system cannot find the file specified.

I'm assuming the yellow highlight is a typo, but where did the leading quote on that same line come from? There doesn't appear to be a trailing quote.

I do not have any explanation. After all the code is extracting existing data; it's not creating anything new. Try not using quotes on the passed parameter, you're using short names anyway so they're not required.

It's unlikely but not unheard of the write cache hasn't emptied out and the file index was not yet updated by the rename.  My guess it's something more obvious. ???
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

ionic

    Topic Starter


    Rookie

    Re: DOS Batch
    « Reply #17 on: January 27, 2008, 10:19:16 AM »
    First off, I think the code we were last working with was:
    Code: [Select]
    Set newname=%RANDOM%.%RANDOM%
    ren %1 %newname%
    DEL %~d1%~p1%newname%
    pause
    exit

    and the info I received in a DOS window with echo on was:

    c:\Documents and Settings\user>Set newname=725.23907
    c:\Documents and Settings\user>ren "C:\Documents and Settings\user\desktop\test.txt" 725.23907
    c:\Documents and Settings\user>DEL C:\Documents and Settings\user\desktop\725.23907
    The system cannot find the file specified.


    They were indeed my typo's. Retying all the info from the dos window gets annoying, i used shout names
    to shorten what I had to type.

    Quote
    Try not using quotes on the passed parameter, you're using short names anyway so they're not required.

    All I am doing is dragging the file I want deleted to the shortcut to the batch file, the quotes on the passed parameters is what DOS spits out as an echo to the commands in the batch file.


    THUS:
    cmd = Set newname=%RANDOM%.%RANDOM%
    echo = D:\Documents and Settings\user>Set newname=725.23907
    cmd = ren %1 %newname%
    echo = C:\Documents and Settings\user>ren "C:\Documents and Settings\user\desktop\test.txt" 725.23907
    cmd = DEL %~d1%~p1%newname%
    echo = C:\Documents and Settings\user>DEL C:\Documents and Settings\user\desktop\725.23907
    The system cannot find the file specified.


    What's interesting is that when the REN cmd is issued the echo uses qoutes on the parameters while when the DEL cmd is issued it does not.

    Bones92,
    Quote
    I ran it from cmd.exe, if that makes a difference...
    Not sure what you mean here, does cmd.exe need to be called from within a batch file? Or ae you saying you types cmd,exe in the run field to open a DOS window? I believe the dos batch file does use cmd.exe for exicution.
    « Last Edit: January 27, 2008, 01:40:57 PM by ionic »

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: DOS Batch
    « Reply #18 on: January 27, 2008, 12:13:22 PM »
    Well at least we're on the same page: ;)

    Code: [Select]
    Set newname=%RANDOM%.%RANDOM%
    ren %1 %newname%
    DEL %~d1%~p1%newname%
    pause
    exit

    Quote
    All I am doing is dragging the file I want deleted to the shortcut to the batch file

    That information would have been helpful from the beginning especially
    Quote
    i used shout names to shorten what I had to type.
    Please read this.

    A quick fix would be to insert the quotes regardless of short or long file names:

    Code: [Select]
    Set newname=%RANDOM%.%RANDOM%
    ren %1 %newname%
    DEL "%~d1%~p1%newname%"
    pause
    exit

     8)

    When Windows 3000 arrives it will probably still support batch code. :o
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    ionic

      Topic Starter


      Rookie

      Re: DOS Batch
      « Reply #19 on: January 27, 2008, 12:39:19 PM »
      OH Sweet Jesus!  That's it!

      Can all the DOS echo responses be piped to a single txt file? For future debugging this would be helpful .

      Beautiful job, wish I could have saved us some time, but I am sorta new with this stuff.

      Thanks for your efforts

      Quote
      When Windows 3000 arrives it will probably still support batch code.

      Don't plan on sticking around to find out!  :o
      « Last Edit: January 27, 2008, 01:55:12 PM by ionic »

      dragonmaster2091



        Rookie

      • If God grows it, we can smoke it.
        Re: DOS Batch
        « Reply #20 on: January 27, 2008, 09:55:57 PM »
        Yeah it seems the only way it will keep a log of its self is if u put an output code (echo %whatever% >> log.txt) and if u click on batch file rather than just drag and drop, but then it only keeps a log of the click, nothing is deleted. Oh and I was wondering how to change it to where it uses the files actual name as a variable apposed to renaming it to random numbers?

        ionic

          Topic Starter


          Rookie

          Re: DOS Batch
          « Reply #21 on: January 28, 2008, 10:33:52 AM »
          DragonMaster,
          Quote
          I was wondering how to change it to where it uses the files actual name as a variable apposed to renaming it to random numbers?

          I'm a bit perplexed as to why you would want to do that???

          I think this might work though:
          Code: [Select]
          Set newname=%1
          DEL %newname%
          exit

          dragonmaster2091



            Rookie

          • If God grows it, we can smoke it.
            Re: DOS Batch
            « Reply #22 on: January 29, 2008, 05:34:35 AM »
            Yeah that worked lol, thanks Ionic!