2

I have a VBScript that reads and records in txt file after pressing the button:

Set myFSO = CreateObject("Scripting.FileSystemObject")
Licznik_ID = myFSO.OpenTextFile("C:\Etykieta_NC\Counter\Counter.txt").ReadAll
Licznik_ID = Licznik_ID + 1
myFSO.OpenTextFile("C:\Etykieta_NC\Counter\Counter.txt",2,True).Write(Licznik_ID)

I would like to create a relative path to the file

"C:\Etykieta_NC\Counter\Counter.txt"

to

"C:\Etykieta_NC\Form"

How to do it in VBScript?

user692942
  • 16,398
  • 7
  • 76
  • 175
darjab
  • 129
  • 1
  • 8

2 Answers2

1

The relevant parts of your filesystem structure look like this:

C:\
└─Etykieta_NC
  ├─Counter
  │ └─Counter.txt
  └─Form

Assuming that you want to create a relative path from the Form subfolder (not to it) the path would go one directory up (..) and then down the Counter subtree:

..\Counter\Counter.txt
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
0

Use GetAbsolutePathName() to build your relative path, here's a quick example

Option Explicit
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim items: items = Array("c:", "c:\test", "c:test", "c:..\Counter")
Dim item, path
For Each item In items
  path = fso.GetAbsolutePathName(item)
  WScript.Echo "Test: PathSpec = " & item & ", Result = " & path
Next
user692942
  • 16,398
  • 7
  • 76
  • 175