Using mkdir in a batch file to create a directory i Program Files(x86

Page 1 of 2 12 LastLast

  1. Posts : 119
    Windows 7 Ultimate
       #1

    Using mkdir in a batch file to create a directory i Program Files(x86


    I am trying to get this batch file to work





    MKDIR C:\Program Files(x86)\NCH Software\NCH Software\Components
    MKDIR C:\Program Files(x86)\NCH Software\NCH Software\Photostage
    MKDIR C:\Program Files(x86)\NCH Software\NCH Software\Disketch
    MKDIR C:\Program Files(x86)\NCH Software\NCH Software\PhotoPad



    but all's I get is this:

    subdirectory or file C:\Program already exists.
    Error occurred while processing: C:\Program.
    A subdirectory or file Files(x86)\NCH already exists.
    Error occurred while processing: Files(x86)\NCH.
    A subdirectory or file Software\NCH already exists.
    Error occurred while processing: Software\NCH.
    A subdirectory or file C:\Program already exists.
    Error occurred while processing: C:\Program.



    how do I rewrite program files(x86) to make this work? John
      My Computer


  2. Posts : 0
    Windows 7 Ultimate x64
       #2

    It's telling you right there the folders from the program you installed from NCH already exists. Can you confirm?

    I use NCH's Wavepad myself, but never had tro use a batch file. Why are you wanting to make a batch file?
      My Computer


  3. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #3

    Not that I understand why you need a batch file, use MKDIR with a "-p" switch placed in your batch file:
    MKDIR -p C:\Program Files(x86)\NCH Software\NCH Software\Components
    MKDIR -p C:\Program Files(x86)\NCH Software\NCH Software\Photostage
    MKDIR -p C:\Program Files(x86)\NCH Software\NCH Software\Disketch
    MKDIR -p C:\Program Files(x86)\NCH Software\NCH Software\PhotoPad
      My Computer


  4. Posts : 7,351
    Windows 7 HP 64
       #4

    The issue is there are names bigger then 8 characters. You have to use path between "
    Ex.:
    MKDIR C:\Program Files(x86)\NCH Software\NCH Software\Components

    replace with

    MKDIR "C:\Program Files(x86)\NCH Software\NCH Software\Components"
    Last edited by Megahertz07; 14 Jul 2020 at 12:45.
      My Computers


  5. Posts : 16,153
    7 X64
       #5

    MD "%programfiles(x86)%\NCH Software\NCH Software\Components"
      My Computers


  6. Posts : 2,468
    Windows 7 Ultimate x64
       #6

    When you have a path with spaces or other special characters inside, you have to enclose it in double quotes. Program files is a common source of problems because of this, often resulting in errors saying "c:\program" missing or similar, just like in your post.
      My Computer


  7. Posts : 3,615
    Win 10 x64, Linux Lite, Win 7 x64, BlackArch, & Kali
       #7

    RBCC

    This what I use to check for CBS folder on desktop, if it exists, delete it, make new folder.

    if exist %UserProfile%\Desktop\CBS (RD /s /q %UserProfile%\Desktop\CBS)
    MD %UserProfile%\Desktop\CBS

    /s Deletes a directory tree (the specified directory and all its subdirectories, including all files).
    /q Specifies quiet mode. Does not prompt for confirmation when deleting a directory tree. The /q parameter works only if /s is also specified.

    Good site for scripts and CMD
    SS64.com
      My Computer


  8. Posts : 2,468
    Windows 7 Ultimate x64
       #8

    Snick said:
    if exist %UserProfile%\Desktop\CBS (RD /s /q %UserProfile%\Desktop\CBS)
    MD %UserProfile%\Desktop\CBS
    This has the very same bug as the OP's code. If the path has any space in it, it'll break with a strange error message about a file not being found, which can happen if the %UserProfile% environment variable has spaces (with a user name with spaces, rare but definitely possible). Like the OP, fix it by enclosing all paths in double quotes.
      My Computer


  9. Posts : 3,615
    Win 10 x64, Linux Lite, Win 7 x64, BlackArch, & Kali
       #9

    Alejandro85

    Thank you for the explanation.

    I've been using that for years, never, ever had a problem.

    However, I will change my code, being that it doesn't break anything.

    Question: Why would someone place a space in the path?
    Bad coding too?
      My Computer


  10. Posts : 7,351
    Windows 7 HP 64
       #10

    Snick said:
    Alejandro85

    Thank you for the explanation.

    I've been using that for years, never, ever had a problem.

    However, I will change my code, being that it doesn't break anything.

    Question: Why would someone place a space in the path?
    Bad coding too?
    @Snick
    This comes from DOS era and 8x3 character limit. Most CMD are from that era.
    You going to find a lot of space characters on windows path
    C:\Program Files
    C:\Windows\Downloaded Program Files
    C:\Windows\Offline Web Pages
      My Computers


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:01.
Find Us