0

I'm not sure if I have used the right expression in the question, but the context totally slips my mind.

I am trying to write a script to go to a student folder, depending on who is logged in, but I don't want to decide all of the folders it must use.

For example - If I want to access student A, I would search

\\Server\Students\Cohort10\user

But student B could be found in

\\Server\Students\Cohort08\user

As you can see, the cohort folders cause a problem for predefined paths because they are different.

So is there a way to type \server\Students\VARIABLE\user

I thought the variable was $ or * or something like that.

1

3 Answers 3

0

If you are using PowerShell:

The * wildcard will match zero or more characters

The ? wildcard will match a single character

[m-n] Match a range of characters from m to n, so [f-m]ake will match fake/jake/make

[abc] Match a set of characters a,b,c.., so [fm]ake will match fake/make

PowerShell wildcards are consistent in their meaning so using . will match any characters followed by a period (.) followed by any characters. In other words . will return only files that have an extension, not directories. To return all items just use a single * This is quite different to the behaviour seen under the CMD shell.

When using WMI filters use the WMI specific wildcards: % for zero or more characters, _ for a single character.

Wildcards will also work within both single and double quotes, to prevent wildcard expansion use the -LiteralPath parameter where available.

Examples

PS C:> Get-ChildItem c:\work*.xls

PS C:> Get-ChildItem c:\work[a-f]*.txt

PS C:> Get-ChildItem -literalpath 'c:\work\test[1].txt'

Source

2
  • in powershell, how would you specify c:\abc\def\.. <-- where .. means the regex .. rather than the go back a directory .. ?
    – barlop
    Aug 24, 2014 at 12:33
  • 1
    The * and ? wildcards work in cmd/batch as well. Jul 6, 2015 at 20:03
0

I think what your looking for is %VARIABLE%, e.g.

echo %TMP%

will replace %TMP% with the value for that environment variable.

0

While there is %USERPROFILE%, Maybe you want something like c:\blah\*\user

cmd can't do c:\blah\*\user

i'm not sure about powershell.

Linux shells eg bash does though.. and you could use cygwin, as cygwin can do it for you, giving you a bash shell in Windows.

Here we have a directory structure of

az\b\sdf\c\
az\b\qwer\c

You can use a wildcard in bash in the middle of a path. This is from cygwin

$ ls -l az/b/*/c
az/b/qwer/c:
total 0

az/b/sdf/c:
total 0

You can access your main files in cygwin by /cygdrive/c/...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .