Need help! (cd ../ mkdir tmp)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
TemplarDrake
Posts: 3
Joined: 17 Mar 2015 03:47

Need help! (cd ../ mkdir tmp)

#1 Post by TemplarDrake » 17 Mar 2015 03:57

Hi guys! First post so be gentle! I am not sure I found the right place, so if I did not please see if you can direct me somewhere I can find the solution!

I am posting for a friend so I don't know all the details. Trying to pack/unpack on Github and for that we need a bat file for Windows.

So far we have:

@echo off
echo Creating temporary storage.
if exist ../tmp/ (del ../tmp) else (cd ../ mkdir tmp)

Everything works but the else-clause gives issues. We tried mkdir ../tmp, but that didn't work neither did cd ../ mkdir tmp.

What we are trying to do is: if ../tmp doesn't exist, create it.

Anyone have an idea?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need help! (cd ../ mkdir tmp)

#2 Post by foxidrive » 17 Mar 2015 04:02

TemplarDrake wrote:What we are trying to do is: if ../tmp doesn't exist, create it.


Code: Select all

md "..\tmp" 2>nul

TemplarDrake
Posts: 3
Joined: 17 Mar 2015 03:47

Re: Need help! (cd ../ mkdir tmp)

#3 Post by TemplarDrake » 17 Mar 2015 04:28

Thanks man!! :lol:

TemplarDrake
Posts: 3
Joined: 17 Mar 2015 03:47

Re: Need help! (cd ../ mkdir tmp)

#4 Post by TemplarDrake » 18 Mar 2015 09:04

Another question!

Need to create subdirectories based on file extensions.

FOR %%i IN (.) DO (
ECHO ..\unpacked\%%~xi
)

The above code provides extension with a period. How can I get rid of the period?

Thanks in advance!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Need help! (cd ../ mkdir tmp)

#5 Post by Squashman » 18 Mar 2015 09:14

Code: Select all

FOR %%i IN (*) DO (
   setlocal enabledelayedexpansion
   set ext=%%~xi
   set ext=!ext:~1!
   ECHO ..\unpacked\!ext!
   endlocal
)

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Need help! (cd ../ mkdir tmp)

#6 Post by Compo » 18 Mar 2015 11:08

Squashman wrote:

Code: Select all

FOR %%i IN (*) DO (
   setlocal enabledelayedexpansion
   set ext=%%i
   set ext=!ext:~1!
   ECHO ..\unpacked\!ext!
   endlocal
)

…Perhaps %%~xi :wink:

Here's a oneliner:

Code: Select all

ForFiles /C "Cmd /C If @IsDir==FALSE If Not Exist ..\unpacked\@Ext MD ..\unpacked\@Ext">Nul


To take it a little further, you could use a similar line to move all files to the respective folder based on their extension:

Code: Select all

ForFiles /C "Cmd /C If @IsDir==FALSE ((If Not Exist ..\unpacked\@Ext MD ..\unpacked\@ext>Nul)&Move /Y @File ..\unpacked\@ext>Nul)"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need help! (cd ../ mkdir tmp)

#7 Post by foxidrive » 19 Mar 2015 18:56

Give this a shot too:

Code: Select all

for %%a in (.) do for /f "delims=." %%b IN ("%%~xa") DO (
ECHO ..\unpacked\%%b
)

Post Reply