2

I can't get this thing to create this hidden folder for the life of me. It completes without any errors just can't get it to create the folder.

 
import os
import ctypes
import subprocess
import urllib
from subprocess import Popen, PIPE, STDOUT

def check_prep (path, stdout, mkdir): path = "C:\Sysprep\sys_prep" stdout = os.path.exists(path) mkdir = os.makedirs(path)

if stdout == "False": FILE_ATTRIBUTE_HIDDEN = 0x02 mkdir ret = ctypes.windll.kernel32.SetFileAttributesW(mkdir, FILE_ATTRIBUTE_HIDDEN)
  • 1
    You are not calling your function, also the local variables in that function will not be available outside of it. – Klaus D. Nov 22 '16 at 05:26

2 Answers2

8

There are many mistakes in the code you posted:

  • path = "C:\Sysprep\sys_prep" => \Sys.. would mean the escape character \S followed by ysprep...; you should use the other slash : C:/Sysprep/sys_prep
  • mkdir = os.makedirs(path) => os.makedirs(path) does not return anything.
  • if stdout == "False": => "False" is a string; what you want is a boolean: just write False (without the quotes).

This should work:

import os
import ctypes


def check_prep(path):
    if not os.path.exists(path):
        os.makedirs(path)
        FILE_ATTRIBUTE_HIDDEN = 0x02
        ret = ctypes.windll.kernel32.SetFileAttributesW(path, FILE_ATTRIBUTE_HIDDEN)


path = "hello/ji"
check_prep(path)
Anmol Singh Jaggi
  • 8,376
  • 4
  • 36
  • 77
2

Hi for creating hidden folders you can simply do.

import os
os.mkdir(".name_of_folder")

Make sure to add "." in front of folder name.