Questions tagged [python-os]

The Python os module provides a portable way of using operating system dependent functionality. Use this tag for questions about using the "os" module.

The Python os module provides a portable way of using operating system dependent functionality.

Links

551 questions
0
votes
0 answers

os.walk() filename scope inside inner loop

Writing a script to help with data migration in renaming images. It seems as though when I try to access the variable filename from within the inner-for-loop, it's just printing .DS_Store See commented lines for example: #!/usr/bin/env python import…
coopwatts
  • 670
  • 1
  • 8
  • 31
0
votes
0 answers

os.rename() gives WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect error

I have written a Python script to rename all files in a folder. The code is: import os import sys import platform walk_dir = dir_path = os.path.dirname(os.path.realpath(__file__)) print('walk_dir = ' + walk_dir) print('walk_dir (absolute) = ' +…
naimul64
  • 133
  • 3
  • 17
0
votes
1 answer

Convert timespec to YYYYMMDD in Python

I am using the .st_birthtime method to get the date of creation of a file. The result looks like: 1359492652 which I can convert to a more readable format 2013-01-29 21:50:52 using datetime.datetime.fromtimestamp(statinfo.st_birthtime) My…
Nicolaesse
  • 2,554
  • 12
  • 46
  • 71
0
votes
2 answers

Reading a text file from within a folder and saving the name of the folder if a particular string is found in the text file - Python

I have about 100 folders with random names, say for this example 1,2,3,4,...100. Inside these folders, I have text files with some strings in them. eg: sample.txt. The text files all have the same name but are in different folders. What I need is to…
aabb bbaa
  • 195
  • 1
  • 3
  • 14
0
votes
1 answer

Backuping files in a dir if they don't already exists

I have a Pathfile.dat with File names within that file, I am trying to copy a backup of the files if one does not exists already I am having an issue with the function " if files.is_file():" Below are the Errors that i seem to be getting…
David
  • 239
  • 2
  • 3
  • 12
0
votes
0 answers

Python attempting to cycle through files and run 5~ windows command prompt commands simultaneously

I've starting a script but for some reason it's not working as intended. I'm trying to cycle through a folder going over all of the files in the folder and making it following command in command prompt for each file: adb install -r…
Ryflex
  • 5,559
  • 25
  • 79
  • 148
0
votes
1 answer

read number of users from OS using python

I am writing a nagios plugin that would exit based on number of users that are logged into my instance. import argparse import subprocess import os import commands import sys if __name__ == '__main__': parser =…
0
votes
0 answers

Merging Multiple (Ideally) JSON Files Into One

Simple enough situation; I'm working from within a directory which contains a script, and a subdirectory at the same level which contains many JSON files. Using ideally Python, I'd like to combine all of the JSON files into one. Depending on your…
user4234032
0
votes
1 answer

how to write tests for a function using py3.5 os.scandir()?

How to write tests to a function using the newly added to build-ins of python 3.5 os.scandir()? Is there a helper to mock a DirEntry objects? Any suggestions on how to mock os.scandir() of an empty folder and a folder with few 2 files for example?
vmenezes
  • 1,076
  • 2
  • 12
  • 21
0
votes
2 answers

How to extract ip in web scanning

While performing a simple task of ip-address extraction, I found that the program is doing well. But in the complete program for web crawling it fail to survive and gives uneven results. This is my code snippet for ip-address: …
Nitin Sharma
  • 57
  • 11
0
votes
1 answer

Simple Python shell wrapper script (using os.execv?)

I want to add a wrapper around a specific shell command. This will run in Linux only and I don't care about cross platform support. This code works, but is there a better way to achieve this? Or am I opening myself up to any weird…
user3827132
  • 129
  • 1
  • 2
  • 9
0
votes
0 answers

Import machine-specific variables from settings.py

I have a file, settings.py that looks like this: import sys import socket import os comp_name = socket.gethostname() if comp_name == 'mymachine.local': DB_VAR=os.environ.get('ENV_VAR') else: print 'update settings.py with global…
aaron
  • 6,339
  • 12
  • 54
  • 80
0
votes
1 answer

os.rename in python return errno 20

I'm writing a little program in python 3 to automatize the ordenation of my downloads folder. when I run it obtain: NotADirectoryError: [Errno 20] Not a directory: '/home/rafa/Descargas/guiaDocente_IA.pdf' -> '/home/rafa/UGR/IA/' I have two…
rafaelleru
  • 367
  • 1
  • 2
  • 19
0
votes
0 answers

os.walk producing inconsistent results

I've been getting some very inconsistent results while using os.walk. My aim is to use python to programmatically locate another python file on my system. This works fine when os.walk doesn't have much work to do and is only searching one or two…
Geord359
  • 3
  • 3
0
votes
1 answer

Getting Error Path does not exist

In my Code I am checking Remote path if not os.path.exists(dest_dir): print "Dest directory does not exist" return But when i access path manually i am able to access. My path is '\\10.223.161.31\D$\images' I have set to…
user2095748
  • 267
  • 1
  • 5
  • 15