Skip to content

Commit

Permalink
Merge pull request #6 from vwbusguy/develop
Browse files Browse the repository at this point in the history
Expand ~/ to ENVIRON$("HOME") for other path commands.
  • Loading branch information
vwbusguy authored Mar 11, 2023
2 parents 4a90e5d + 248265c commit 325eb83
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions qbsh.bas
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ Return
'Delete a file path
DEL:
pathspec$ = args$
If InStr(pathspec$, "~") = 1 And InStr(pathspec$, "/") = 2 Then
pathspec$ = Environ$("HOME") + "/" + Right$(pathspec$, Len(pathspec$) - 2)
End If
If _FileExists(pathspec$) Then
On Error GoTo DELERR
Kill pathspec$
Expand Down Expand Up @@ -258,9 +261,13 @@ Return
'Make a new directory
MAKEDIR:
If args$ <> "" Then
dir$ = args$
If InStr(dir$, "~") = 1 And InStr(dir$, "/") = 2 Then
dir$ = Environ$("HOME") + "/" + Right$(dir$, Len(dir$) - 2)
End If
If dir$ <> "" Then
On Error GoTo MAKEDIRERR
MkDir args$
MkDir dir$
Else
Print "MAKEDIR <New Directory Path>"
End If
Expand All @@ -284,6 +291,12 @@ If args$ = "" Or InStr(args$, "=") < 2 Then
End If
dest$ = Left$(args$, InStr(args$, "=") - 1)
src$ = Right$(args$, Len(args$) - InStr(args$, "="))
If InStr(dest$, "~") = 1 And InStr(dest$, "/") = 2 Then
dest$ = Environ$("HOME") + "/" + Right$(dest$, Len(dest$) - 2)
End If
If InStr(src$, "~") = 1 And InStr(src$, "/") = 2 Then
src$ = Environ$("HOME") + "/" + Right$(src$, Len(src$) - 2)
End If
If Not _FileExists(src$) Then
If _DirExists(src$) Then
Print src$; " is a directory. Only regular files are supported for the source."
Expand Down Expand Up @@ -378,6 +391,9 @@ Return
'This sub reads a file.
READFILE:
tmpfileloc$ = args$
If InStr(tmpfileloc$, "~") = 1 And InStr(tmpfileloc$, "/") = 2 Then
tmpfileloc$ = Environ$("HOME") + "/" + Right$(tmpfileloc$, Len(tmpfileloc$) - 2)
End If
If Not _FileExists(tmpfileloc$) Then
Print "File not found."
Return
Expand All @@ -398,6 +414,9 @@ Return
'Remove directory
REMDIR:
path$ = args$
If InStr(path$, "~") = 1 And InStr(path$, "/") = 2 Then
path$ = Environ$("HOME") + "/" + Right$(path$, Len(path$) - 2)
End If
If path$ <> "" And _DirExists(path$) Then
On Error GoTo REMDIRERR
RmDir path$
Expand Down Expand Up @@ -425,6 +444,12 @@ Else
sourcepath$ = _Trim$(Left$(args$, InStr(UCase$(args$), " AS ")))
targetpath$ = _Trim$(Right$(args$, Len(args$) - (InStr(UCase$(args$), " AS ") + 3)))
End If
If InStr(sourcepath$, "~") = 1 And InStr(sourcepath$, "/") = 2 Then
sourcepath$ = Environ$("HOME") + "/" + Right$(sourcepath$, Len(sourcepath$) - 2)
End If
If InStr(targetpath$, "~") = 1 And InStr(targetpath$, "/") = 2 Then
targetpath$ = Environ$("HOME") + "/" + Right$(targetpath$, Len(targetpath$) - 2)
End If
If InStr(UCase$(args$), " AS ") = 0 And InStr(targetpath$, " ") > 0 Then
Print "Syntax for paths with spaces: RENAME file/dir AS new name"
Return
Expand Down

0 comments on commit 325eb83

Please sign in to comment.