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
3 answers

find the new path after using os.system('cd')

I'm trying to generate windows CMD using os. After I change the directory using os.system('cd other_dir'), how can I find the new directory, using os?
Daniel
  • 229
  • 1
  • 8
0
votes
1 answer

Renaming a file one another disk

My python script is on partition D and I want to rename files in folders on partition E: I can't move the folder/files to D, because of limited space. path= "E:\\A" for f in os.listdir(path): f_name, f_ext = os.path.splitext(f) empty,…
user3541631
  • 3,686
  • 8
  • 48
  • 115
0
votes
1 answer

Finding the exact directory of the file in Python

Have a Pandas dataframe with the list of file names: Files 3003.txt 3000.txt Also having three directories in which I'd like to make search for these files: dirnames=[ '/Users/User/Desktop/base/reports1', …
Keithx
  • 2,994
  • 15
  • 42
  • 71
0
votes
1 answer

Appending the results of for loop with if statement to Pandas Dataframe in Python

I'm making a script in Python for searching for the selected term (word/couple words, sentence) in a bunch of .txt files in a selected folder with printing out the names of the .txt files which contain the selected term. Currently is working pretty…
Keithx
  • 2,994
  • 15
  • 42
  • 71
0
votes
1 answer

Python Text Searching in .txt files in different folders with printing the name of file and folder

I'm making a script in Python for searching for the selected term (word/couple words, sentence) in a bunch of .txt files in a selected folder with printing out the names of the .txt files which contain the selected term. Currently is working pretty…
Keithx
  • 2,994
  • 15
  • 42
  • 71
0
votes
2 answers

os.walk one level down

I have a folder (A) that is structured like this: A\b A\c A\d I would like to copy folder b, c, and d one level down 3 times like this: A\b\b1\b2\b3 A\c\c1\c2\c3 A\d\d1\d2\d3 Where b1,b2, and b3 are copies of the folder b, the same goes for c and…
lamaee201
  • 21
  • 6
0
votes
1 answer

Transforming function for reading txt files into one string to document logics

Have a bunch of .txt files in the folder. Here are two functions which are using for reading these files and saving them into a variable as one string: s=(glob.glob("/Users/user/documents/folder/*.txt")) def read_files(files): for filename in…
Keithx
  • 2,994
  • 15
  • 42
  • 71
0
votes
1 answer

Execute second python script only when the first script is done

I execute python script from browser via lua script: os.execute('python scriptname.py --arg1 Test --arg2 Test2') and I do it again (e.g. by refreshing the page, sending the form) os.execute('python scriptname.py --arg1 Test3 --arg2 Test4') I would…
kst
  • 51
  • 1
  • 4
0
votes
1 answer

Saving the .txt files in another folder in Python

Have some lightweight text search engine. It iterates through the .txt files in one folder, searches for selected term and displays the name of the file. All is based on the functionality of os library: import os dirname =…
Keithx
  • 2,994
  • 15
  • 42
  • 71
0
votes
2 answers

Python os.popen() returns running process count incremented by 1

I have tried to get process count by using ps, when I execute command on my linux terminal it returns correct count. But when I am executing same command in python shell using os.popen(), then the returned count is always incremented by one…
Sanket
  • 744
  • 7
  • 22
0
votes
1 answer

Get system file type names python

Is there any way to retrieve a file type name in Python using the OS module? An example made up command: >>> os.file_type('txt') Would return: 'Text Document' Any help would be appreciated :) Oscar.
Oscar Peace
  • 99
  • 1
  • 2
  • 11
0
votes
1 answer

os.path.isdir() is not working

os.path.isdir() is returning false even when i'm passing a directory path to the function. i'm anexing the code snippet. the code creates a folder called "arquivos" , to test, just create some files / folders inside. import os class Arquivos(): …
WagnerAlbJr
  • 190
  • 1
  • 12
0
votes
2 answers

Not able to execute terminal command(top) in python

I have this command: top -d 1.0 -n 1| grep Mem when i execute it in terminal i get: KiB Mem : 16330216 total, 3902792 free, 10619512 used, 1807912 buff/cache KiB Swap: 8509436 total, 4584448 free, 3924988 used. 4848204 avail Mem I want to…
Shubham R
  • 7,382
  • 18
  • 53
  • 119
0
votes
1 answer

Sending Terminal commands from a running script on remote back to my local?

I'm developing on a remote server which I login using ssh and develop using vi. I however need to send Terminal notification commands osascript -e "display notification {} {} {}" and such commands back to my local terminal so I can get sound/mac…
Deepak
  • 149
  • 1
  • 1
  • 11
0
votes
1 answer

Why does appending to a list take forever?

I wrote the following code: import fnmatch ll = [] for items in src: for file in os.listdir('/Users/swaghccc/Downloads/PulledImages/'): if fnmatch.fnmatch(file, items.split('/')[-1]): print file …
TheTank
  • 495
  • 2
  • 9
  • 21