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?
Need help! (cd ../ mkdir tmp)
Moderator: DosItHelp
Re: Need help! (cd ../ mkdir tmp)
TemplarDrake wrote:What we are trying to do is: if ../tmp doesn't exist, create it.
Code: Select all
md "..\tmp" 2>nul
-
- Posts: 3
- Joined: 17 Mar 2015 03:47
Re: Need help! (cd ../ mkdir tmp)
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!
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!
Re: Need help! (cd ../ mkdir tmp)
Code: Select all
FOR %%i IN (*) DO (
setlocal enabledelayedexpansion
set ext=%%~xi
set ext=!ext:~1!
ECHO ..\unpacked\!ext!
endlocal
)
Re: Need help! (cd ../ mkdir tmp)
Squashman wrote:Code: Select all
FOR %%i IN (*) DO (
setlocal enabledelayedexpansion
set ext=%%i
set ext=!ext:~1!
ECHO ..\unpacked\!ext!
endlocal
)
…Perhaps %%~xi
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)"
Re: Need help! (cd ../ mkdir tmp)
Give this a shot too:
Code: Select all
for %%a in (.) do for /f "delims=." %%b IN ("%%~xa") DO (
ECHO ..\unpacked\%%b
)