0

I am using Vizard to create an .exe file off a python script. I need this script to create a folder which resides next to the .exe file

if getattr(sys, 'frozen', False):
    logging.warning('Application is exe')
    loggingPath = os.path.dirname(sys.executable)
    logging.warning(os.getcwd())
elif __file__:
    loggingPath = os.path.dirname(__file__)
    logging.warning('Application is script')
    logging.warning(os.getcwd())

if not os.path.exists(loggingFolder):
    logging.warning('Directory not existing... creating..')
    os.makedirs(loggingFolder)

works fine when I execute from the IDE, but in an exe file it throws data in the Appdata Folder in Windows/Users/Temp/randomfoldername.

Also, I always Application is script, even when its packed into exe.

Can someone point me in the right direction here? Thanks in advance

coernel
  • 79
  • 1
  • 9
  • What output do you get when running this? – M.T May 13 '16 at 11:29
  • Both when executing it from the ide and as executable, what is the output? – M.T May 13 '16 at 11:41
  • When I execute from IDE: WARNING:root:Application is script WARNING:root:G:\WakefulRest WARNING:root:G:\WakefulRest I know it says warning because I use loglevel warning, G is the usb drive. From the exe: The same output, but with a path to my user folder in windows. – coernel May 13 '16 at 11:45

2 Answers2

1

The sys module does not have any attribute frozen, which results in the first if statement always returning False.

sys.executable will give the path to the python interpreter binary, ie. for Windows the path of your python.exe file, which I cannot see why you would need for this.

If what you want is to ensure that the file running is a .exe file, then make a folder next to it, it may be simpler to just check if the filename ends with .exe?

if __file__.endswith('.exe'):
    loggingFolder = os.path.join(os.path.dirname(__file__), 'foldername')
    if not os.path.exists(loggingFolder):
        os.makedirs(loggingFolder)
M.T
  • 4,917
  • 4
  • 33
  • 52
0

if you just want to create a folder at runtime, then another (possibly easier) method is to run your vizard program from within a batch file and create the folder first in the batch file

e.g. create run_viz_prog.bat with content like this :-

mkdir new_folder
my_viz_prog.exe
jacanterbury
  • 1,435
  • 1
  • 26
  • 36