2

I've done a little batch that create a folder with the current date (year/month/day). This is the code:

mkdir %date:~-4,4%_%date:~-7,2%_%date:~0,2%

but it doesn't work when I use it in a network folder for exemple in "\192.168.1.100\01-SCHEMA"

What can i do? Thanks! :) Dennis

2
  • 1
    Your can add UNC full path before the folder you want to create in your code. Use \\192.168.1.100\... instead of \192.168.1.100\.... For example, md "\\192.168.1.100\...\your folder" Commented Apr 27, 2016 at 14:21
  • 1
    pushd supports UNC paths, type pushd /? to find out how it works... Commented Apr 27, 2016 at 14:31

2 Answers 2

5

Assign the network share a temporary drive letter and work on that:

NET USE Z: \\192.168.1.100\01-SCHEMA
mkdir z:\%date:~-4,4%_%date:~-7,2%_%date:~0,2%
NET USE Z: /DELETE

Or a bit easier, let PUSHD / POPD do the same for you:

PUSHD \\192.168.1.100\01-SCHEMA
mkdir %date:~-4,4%_%date:~-7,2%_%date:~0,2%
POPD

Another possibility, from a now deleted comment, is to use the entire network path in the command:

mkdir \\192.168.1.100\01-SCHEMA\%date:~-4,4%_%date:~-7,2%_%date:~0,2%

Update/Follow-up: The general way in this situation - as asked - would be to evaluate all network shares and iterate over them. If you're sure that you really want to include all shares, use the code below (needs to be put in a .bat file). Use NET VIEW \\192.168.1.100 to check the list of shares beforehand.

@ECHO OFF
SET HOST=192.168.1.100
FOR /F "tokens=1" %%G IN ('NET VIEW \\%HOST% ^| FINDSTR Disk') DO (
    MKDIR "\\%HOST%\%%G\%date:~-4,4%_%date:~-7,2%_%date:~0,2%"
)

Follow-up #2: In order to programatically create the folder over/on a network share independent of the actual network path, this single line will suffice:

MKDIR "%~dp0%date:~-4,4%_%date:~-7,2%_%date:~0,2%"

It works because %~dp0, which is expanded to drive letter and path of the currently running script, will give you the UNC-path if run from a network share. So this solution does more or less resemble method #3 of the first part of this answer.

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you very much!! :) Is it possibile to have relative paths? I have that file in a lot of folders.. Have I to modify all of them with the assolute path or there is a faster and general way? (I've it in \\192.168.1.100\01-SCHEMA , \\192.168.1.100\02-CALCOLO and so on) Thanks :)
@DennisGrasso: Basically yes, but the problem is that the "directories" you want process are actually shares (\\[HOST]\[SHARE]\[DIRECTORY]). You need to get a list of those first. If you really want to create the directory everywhere, it's easy, otherwise things will probably get ugly quick.
@DennisGrasso: added a generic solution.
Hello @zb226 , thanks for your support! I didn't was too much clear.. This is the situation: I've a server at //192.168.1.100 In this location I've a folder called PROJECTS Inside it all my projects with a prefix number (ex. 9226_Hospital, 9227_School and so on) When I have to create a new project I'll copy and past a general folder XXXX_PROJECT which I'll rename. Inside that folder I've my batch. In order to create the folder inside that, even when i rename the main folder. Is it possible without changing everytime the batch file? Thanks!! :) Dennis
@DennisGrasso: now I understand your requirement. Updated the answer once more...
|
0

E:\Test\New folder>mkdir "E:\Test\New Folder\""Creating Test Folder"

Do not keep any space between "".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.