Skip to content

StringPath for simulating a 'cd' command on a path-like string

License

Notifications You must be signed in to change notification settings

PascalVallaster/stringpath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Stringpath for treating a string as a path

About stringpath

stringpath is a python script for simulating the 'cd' command on a string that contains a path.

Please report errors directly to my email: [email protected]


Install

Download:

Download with git:

https://github.com/PascalVallaster/stringpath.git

or download the ZIP file.

Install dependencies:

  • Python 3.4^
    • Standard Library

Usage

Basic usage example

from stringpath import change_directory

cwd = r"C:\my/current\path"
cd = r"..\i/want\to\cd/in/here"
new_cwd = change_directory(cwd, cd)

For more usage details see the docs in the functions itself

Use Case example

Imagine your program has to execute sys-commands in different (user-depending) directories with subprocess which will be determined by the user using the command 'cd'. The problem is, you don't want to change the current working directory in order to avoid problems and security threats. This tool allows you to accomplice that.

Example:

import subprocess
import stringpath

command = "dir"
cwd = "C:/MyFiles/MyAppFolder/"
print("'cd' into a different location")
cd = input(cwd + ">")
cwd = stringpath.change_directory(cwd, cd)
subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cwd)

About

StringPath for simulating a 'cd' command on a path-like string

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages