Mostly Linux & Python syntax notes and hyperlinks.

Friday, August 9, 2019

Windows - using %CD% for current directory and levels

For windows scripting, you can access levels above %CD%. Just remember to use backslash, not forward slash:

C:\Users\mharrison>echo %CD%
C:\Users\mharrison
C:\Users\mharrison>dir %CD%\..\..
 Volume in drive C is Windows
 Volume Serial Number is E431-FA9F
 Directory of C:\
03/03/2017  11:02 AM    <DIR>          DRIVERS
04/11/2018  07:38 PM    <DIR>          PerfLogs
05/31/2019  02:25 PM    <DIR>          Program Files
05/15/2019  09:04 AM    <DIR>          Program Files (x86)
03/25/2019  05:33 PM    <DIR>          test
05/13/2019  10:56 AM    <DIR>          Tools
04/09/2019  09:21 AM    <DIR>          Users
08/08/2019  06:02 PM    <DIR>          Windows
               0 File(s)              0 bytes
               8 Dir(s)  61,991,501,824 bytes free

C:\Users\mharrison>dir %CD%/..
Invalid switch - "..".

Also, check out this great tool for formatting code for blogging on blogger:
http://formatmysourcecode.blogspot.com/