Search code examples
python-3.xfilekeylogger

How to place a new file in a certian place on hard drive (python)


I am making a full python keylogger. It undergoes a simple processes. First store keystrokes inside a file on startup. Next, find the file and send the file across WiFi. Lastly, shutdown. For this to work I need to make a file for the keylogger to send the keystroke information to. I tried using:

open('myfile', 'w+')

This will create my file but how do I place my file into a certain place?

Extra Information:

Python 3.7x


Solution

    • You can add the path to the filename:

      open('/users/myname/myfile.txt', 'w+')
      open('C:\\Public\\myfile.txt', 'w+')
      
    • Or, you can change your current directory:

      import os
      os.chdir('/tmp/')
      open('myfile.txt', 'w+')
      

      Both should work! Happy Coding!