1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Trying to combine 2 batch commands -> 1 file...

Discussion in 'Software Development' started by SirLaffsalot, Dec 15, 2011.

Thread Status:
Not open for further replies.
  1. SirLaffsalot

    SirLaffsalot Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    1
    :eek: I'm in the middle of using 2 batch files to rename files, like so:

    The first script deletes all filename characters, except the first 2, as I want, IF I HIDE FILE EXTENSIONS BEFORE EXECUTING (that's another issue I think).
    ==================================
    Setlocal EnableDelayedExpansion

    For %%A In ( "K:\01_02A") Do (

    PushD "%%A"

    For /F "Tokens=1 Delims=" %%I In ('dir /A-D /B *') Do (

    Set _tmp=%%I

    Set _tmp=!_tmp:~0,2!

    Ren "%%I" "!_tmp! "

    )

    PopD

    )
    =============================================
    More ancillary info: this above script makes the file, an MPEG file, un-identifiable to Windows. The icon for the file changes to indicate that it is un-associated with an app to open it.

    SO...

    I THEN use the second script to add TO the new 2-digit filename, 5 characters that restores the recognition of the file type, and its' association with an application (the icon changes back), and of course, the extension hides itself as I at first had it set.
    =======================================
    Setlocal EnableDelayedExpansion

    For %%A In ( "K:\01_02A") Do (

    PushD "%%A"

    For /F "Tokens=1 Delims=" %%I In ('dir /A-D /B *') Do (

    Set _tmp=%%I

    Set _tmp=!_tmp:~0,-3!*.mpeg!

    Ren "%%I" "!_tmp! "

    )

    PopD

    )
    =============================================

    What will a file look like with functions combined???

    Thanks..............
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    I am not understanding why you would want them combined. I assume you are changing the extension so that it doesn't open with a program when you double click the file. So the 2nd script restores the original file association. I am not sure why you would want to do this in one script. Doesn't make any logical sense to me.
     
  3. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Not sure why you have the 1st for Loop. Doesn't do anything other than putting the only directory you are processing in to a variable. You could just do a pushd with the directory name without using the FOR Loop.

    The 2nd script doesn't even need to use Delayed Expansion. If you use the command modifiers you don't even need to use the set statements. I would even go as far as to say if you just didn't even worry about removing only part of the extension in the 1st script you wouldn't even need to use Delayed expansion in that script either. Your DIR command uses a wild card to find all files in both scripts so its not like you are just looking for MPEG files. It seems like MPEG's are the only files in that directory. So why not just completely remove the extension in the 1st script using the command modifiers and then put the extension back on in the 2nd script.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1031425

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice