Looking for ideas to help me with this.
I have a lot of music and most of it is in order of [artist folder] [album folder] [cd folder] [files] and I want to quickly be able to bring all music files under [artist] level.
I'm not expecting miracles so I'm thinking if I can set it up as a right click command much like WinRar does with Extract Here, that should bring everything from that folder up a level?
So I need to be able to
call my batch , and pass it the target folder.
Have the batch select all files/folders within and move to the
same level as target folder.
Trying to keep it simple even if I need to r/click several times for one artist!
Thanks in advance for any help, pointers or further reading!
Here is a script to move all files under a root directory to the root.
"Moveit.bat C:\my\music"
will find everything under that directory and move them into C:\my\music.
Line 27 is commented out ... so the script will only tell you what it would do.
Uncomment line 27 for it to actually work.
#echo off
#rem USAGE: MoveIt root
setlocal
pushd "%~1"
set root=%CD%
if "%1"=="" goto :Usage
for /f "delims=;" %%a in ('dir /a-d /b /s ') do call :MoveIt "%%a"
goto :EOF
:MoveIt
rem Exclude files directly under "from"
set target=%~d1%~p1
if "%target:~2%"==":\" (
if "%target%"=="%root%" (
goto :EOF
)
) else if "%target:~0,-1%"=="%root%" (
goto :EOF
)
echo move "%~1" "%root%"
rem move "%~1" "%root%" > nul || echo Failed to move "%~1" to "%root%" & goto :EOF
goto :EOF
:Usage
echo Usage: moveit.bat RootDirectory
goto :EOF
Related
I have some PDF files that I need to rename and move to specific folders to be able to import into a system.
The file by default has the following name:
ex: 12345.123456/1234-12.pdf
First I need to remove the characters "," "/" "-"
#echo off
setlocal EnabledelayedExpansion
for /r "C:\importation" %%a in (*) do (
set "newname=%%~na"
set "newname=!newname:.=!"
set "newname=!newname:-=!"
set "newname=!newname:/=!"
ren "%%~a" "!newname!%%~xa"
)
Now I need to create folders with the filename (without the characters removed, ex: 12345123456123412) and rename them to the following pattern:
ex: P12345123456123412_V1_A0V0_T07-54-369-664_S00001_Volume.pdf
For that I drag the files to the following script:
#If Not "%~1" == "" For %%G In (%*) Do #MD "%%~dpG%%~nG" 2>NUL && Move /Y "%%~G" "%%~dpG%%~nG\P%%~nG_V1_A0V0_T07-54-369-664_S00001_Volume%%~xG"
I would like to do only one process, that is, join the two scripts and run only once.
Can someone help me?
Rather than dragging the files to the batch file I would like to run it and have it read the files (.pdf) from the folder
Is something like this what you are looking for?
The following will accept drag and drop of one or more files or directories, (subject to command line length restrictions). Each individually dropped PDF file and each PDF file within any dropped directory should be processed as requested.
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
If "%~1" == "" GoTo :EOF
For %%G In (%*) Do (For %%H In ("%%~G") Do If "%%~aH" Lss "-" (
Echo Error! %%G no longer exists.
%SystemRoot%\System32\timeout.exe /T 2 /NoBreak 1>NUL
) Else If "%%~aH" GEq "d" (For %%I In ("%%~G\*.pdf") Do Call :Sub "%%~I"
) Else If /I "%%~xG" == ".pdf" (Call :Sub "%%~G"
) Else (Echo Error! %%G is not a PDF
%SystemRoot%\System32\timeout.exe /T 2 /NoBreak 1>NUL))
GoTo :EOF
:Sub
Set "basename=%~n1"
Set "basename=%basename:.=%"
MD "%~dp1%~n1" 2>NUL
If Not ErrorLevel 1 Move /Y %1 "%~dp1%~n1\P%basename:-=%_V1_A0V0_T07-54-369-664_S00001_Volume%~x1"
Exit /B
Please note, as the character / is invalid in file or directory names, I have ignored that part of your question.
I have some pdf's in a folder that I need to organize them like this:
PDF name: 123.12.123.pdf ; 102030_01.pdf; 102030_02.pdf; 123.4512.34561.23412.pdf
Now I need to create folders with the filename (without the characters removed, ex: 12345123456123412) and rename them to the following pattern: ex: P12345123456123412_V1_A0V0_T07-54-369-664_S00001.pdf
for this I have used the following code which works very well:
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
If "%~1" == "" GoTo :EOF
For %%G In (%*) Do (For %%H In ("%%~G") Do If "%%~aH" Lss "-" (
Echo Error! %%G no longer exists.
%SystemRoot%\System32\timeout.exe /T 2 /NoBreak 1>NUL
) Else If "%%~aH" GEq "d" (For %%I In ("%%~G\*.pdf") Do Call :Sub "%%~I"
) Else If /I "%%~xG" == ".pdf" (Call :Sub "%%~G"
) Else (Echo Error! %%G is not a PDF
%SystemRoot%\System32\timeout.exe /T 2 /NoBreak 1>NUL))
GoTo :EOF
:Sub
Set "basename=%~n1"
Set "basename=%basename:.=%"
MD "%~dp1%~n1" 2>NUL
If Not ErrorLevel 1 Move /Y %1 "%~dp1%~n1\P%basename:-=%_V1_A0V0_T07-54-369-664_S00001_Volume%~x1"
Exit /B
I drag the pdfs into the .bat and it does the adjustment.
It happens that there is a case that I am not able to handle. Some pdfs need to be in the same folder, for example in the following case:
PDF name: 102030_01.pdf; 102030_02.pdf;
Note that the pdfs have the same number, only after the _ that we have the difference. In this case you would need to create a folder with the name:102030
And move the two files into it, modifying their name as follows:
102030_01.pdf -> P102030_V1_A0V0_T07-54-369-664_S00001.pdf
102030_02.pdf -> P102030_V1_A0V0_T07-54-369-664_S00002.pdf
Could anyone help?
:Sub
Set "basename=%~n1"
Set "basename=%basename:.=%"
if /i "%basename%" neq "%basename:_=%" goto sub2
MD "%~dp1%~n1" 2>NUL
If Not ErrorLevel 1 Move /Y %1 "%~dp1%~n1\P%basename:-=%_V1_A0V0_T07-54-369-664_S00001_Volume%~x1"
Exit /B
:sub2
for /f "tokens=1*delims=_" %%b in ("%basename%") do (
MD "%~dp1%%b" 2>NUL
ECHO Move /Y %1 "%~dp1%%b\P%basename:-=%_V1_A0V0_T07-54-369-664_S000%%c_Volume%~x1"
)
Exit /B
Always test on dummy data first.
This code echoes the proposed move. After verification, remove the echo keyword to activate.
Caution: My reading of the code is that - should be removed from the basename in the new name, and that _Volume should be appended to the name part, which is not shown in your examples.
Essentially, if the basename contains _ then goto sub2.
sub2 partitions the name in basename, assigning the first part to %%b and the second to %%c (See for /? from the prompt for documentation)
Then the directory is created
The md will object if the directory already exists, hence the 2>nul in the original code (suppresses error messages)
If md found that error in the original then this appears to be a problem, so the move is not executed. In the new version, it is expected that the directory may already exist, so the errorlevel processing has been removed.
can someone please help how to find specific folders with size 0 under directory using batch? thank you.
there are many folders in a parent folder, some of them have files inside and some folder are empty. I'd like to find out the name of the empty folders using batch file. can someone help? thanks
This script scans the target folder and returns the UNC paths of all empty subfolders within the target folder.
#echo off
setlocal EnableDelayedExpansion
REM This script scans the target folder and returns the UNC paths of all empty subfolders within the target folder.
title Looking for empties, please wait!
cd "%~dp0"
cls
if "%~1" == "" (
echo ERROR: No folder was specified! You gotta tell me where to look for empties!
echo Please drag-and-drop a folder onto the icon for this script.
pause
exit /b
)
if not exist "%~dpn1" (
echo ERROR: The folder you told me to scan doesn't seem to exist!
pause
exit /b
)
set "target=%~dpn1"
echo Scanning: %target%
echo.
REM Grab each subfolder for checking.
for /f "tokens=*" %%a in ('dir "%~dpn1" /s /b /a:d') do (call :checkForBlanks "%%a")
echo.
echo Done.
title Done.
pause
exit /b
:checkForBlanks
REM We've been given a folder. We must check if it's empty.
set "folder=%~1"
set "scanned=!folder:%target%=!"
title Looking for empties: %scanned:&=^&%
set exist=
for /f %%a in ('dir "%~1" /b') do (set "exist=%%a" & goto :found)
:found
if "%exist%" == "" echo EMPTY: %scanned:&=^&%
goto :eof
The following batch-file idea, which leverages powershell may provide the information you require.
I say, may, because you've not clarified what you deem to be an empty subfolder, or folder with size 0.
The following single line batch file example should work regardless of the installed powershell.exe version:
#(For /F "Delims=" %%G In ('%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoP "(GCI -Rec|?{$_.PSIsContainer -Eq $True})|?{$_.GetFileSystemInfos().Count -Eq 0}|Select -Exp FullName" 2^>NUL')Do #Echo/%%G)&Pause
If you're using a more up to date version of powershell.exe, perhaps the following example may be preferable for you:
#(For /F "Delims=" %%G In ('%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoP "GCI -AD -S|?{$_.GetFileSystemInfos().Count -Eq 0}|Select -Exp FullName" 2^>NUL')Do #Echo/%%G)&Pause
Both examples are designed to recurse from the current directory, if you wish to insert the base directory directly into the for loop then use it just after GCI in whichever example you choose, (preferable enclosed between single straight quotes)
Sorry if this is a big face palm for you guys. I'm a beginner, just trying to save some time.
I have some .bnk files that I'd like to run through a few steps to extract the audio out of the files. My problem is, the extracted files overwrite each other as they are created and I'm trying to get the extracted files into it's own folder.
Here's my current batch file:
FOR %%a IN ("Game Files\*.BNK") DO (MD "%%~na" 2>nul)
FOR %%b IN ("Game Files\*.BNK") DO ("Tools\bnkextr.exe" "%%b" & MOVE *.wav "Tools\Decoding")
FOR %%c IN (Tools\Decoding\*.WAV) DO ("Tools\ww2ogg.exe" "%%c" --pcb Tools\packed_codebooks_aoTuV_603.bin & DEL "%%c")
FOR %%d IN (Tools\Decoding\*.OGG) DO ("Tools\revorb.exe" "%%d" & MOVE "%%a" "%%~na")
FOR %%f IN ("Game Files\*.BNK") DO (DEL "%%f")
echo BNK files deleted, enjoy your unpacked audio!
pause
exit
I have multiple .bnk files in the \Game Files\ folder, for example:
GameSoundFX.bnk
GameMusic.bnk
The first line of my code creates a new folder based on the filename of the .bnk.
FOR %%a IN ("Game Files\*.BNK") DO (MD "%%~na" 2>nul)
The next three lines puts the .bnk through a series of extraction and codec processes. First it creates multiple .wav files and then it converts them in to .ogg files. I'd like it to then move those .ogg files into the relevant folder so I end up with something like this..
\GameSoundFX\0001.ogg
\GameSoundFX\0002.ogg
\GameSoundFX\0003.ogg
\GameMusic\0001.ogg
\GameMusic\0002.ogg
\GameMusic\0003.ogg
But the problem is...
1) the first line creates all the folders first
2) the second line creates all the .wav files (and .wav files from the second .bnk file overwrite the first)
3) the fourth line doesn't move the files into the correct folder. they remain in \Tools\Decoding\
So, I guess my question is, how can I get this batch file to run through the process with each .bnk file ONE AT A TIME and then place the .ogg files into the folder we create with the first line of code?
You can easily nest your commands to make sure it processes one file at a time. When you nest commands inside parenthesesized code blocks it helps to indent the code so you know what belongs to what. I am unsure what some of your code is doing and I made a comment in my code accordingly. See if this helps.
#ECHO off
FOR %%a IN ("Game Files\*.BNK") DO (
MD "%%~na" 2>nul
Tools\bnkextr.exe" "%%a"
MOVE *.wav "Tools\Decoding"
FOR %%c IN (Tools\Decoding\*.WAV) DO (
"Tools\ww2ogg.exe" "%%c" --pcb Tools\packed_codebooks_aoTuV_603.bin
DEL "%%c"
)
FOR %%d IN (Tools\Decoding\*.OGG) DO (
"Tools\revorb.exe" "%%d"
REM ##### Unsure what you are trying to move here ####
MOVE "%%d" "%%~na"
)
REM Deleting the .BNK file
DEL "%%a"
)
pause
exit
Avoid multi-command blocks/lines of code (nesting, & and &&) where possible. It makes things easier to follow when debugging and it's just plain easier to get it right the first time.
Untested:
#setlocal EnableExtensions
#set _decodingDir=Tools\Decoding
#for %%I in ("Game Files\*.BNK") do #call :ProcessBNK "%%I"
#exit /b
:ProcessBNK
#set _targetDir="%~n1"
#md %_targetDir% 2>nul
#Tools\bnkextr.exe %1
#move *.wav %_decodingDir%
#for %%I in (%_decodingDir%\*.WAV) do #call :ProcessWAV "%%I"
#for %%I in (%_decodingDir%\*.OGG) do #Tools\revorb.exe "%%I"
#move %_decodingDir%\*.ogg %_targetDir%
#move %1 %_targetDir%
#exit /b
:ProcessWAV
#Tools\ww2ogg.exe %1 --pcb Tools\packed_codebooks_aoTuV_603.bin
#del %1
#exit /b
Remove leading # symbol to show lines when debugging (assumes echo is on in your command window).
Thanks jwdonahue!
Your code almost worked. I just had to adjust a little bit because the .ogg files remained in \Tools\Decoding. I tested it with multiple .bnk files in \Game Files\ and it worked! Thankyou so much.
setlocal EnableExtensions
for %%I in ("Game Files\*.BNK") do call :ProcessBNK "%%I"
exit /b
:ProcessBNK
set _targetDir="%~n1"
md %_targetDir% 2>nul
Tools\bnkextr.exe %1
move *.wav Tools\Decoding
for %%I in (Tools\Decoding\*.WAV) do call :ProcessWAV "%%I"
for %%I in (Tools\Decoding\*.OGG) do Tools\revorb.exe "%%I"
move Tools\Decoding\*.OGG %_targetDir%
move %1 %_targetDir%
exit /b
:ProcessWAV
Tools\ww2ogg.exe %1 --pcb Tools\packed_codebooks_aoTuV_603.bin
del %1
exit /b
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Delete files in subfolder using batch script
I have to delete .txt files from a sub folder (with same name). My filepath is like as follows.
d:\test\test1\archive*.txt
d:\test\try\archive*.txt
d:\test\model\archive*.txt
I tried "del" command to delete the ".txt" files in above paths. But there are more than 100 folders in the folder "test". So it is very difficult to use "del" for each and every path.
Except the parent folder name of "archive" folder, everything remains the same for all the paths. So I guess there might be some easy way to delete the files using batch script.
Can anyone guide me whether there is any easy way to delete .txt files using batch script Or I have to repeat "del" for all 100 folders?
del /s *.txt
hope it helps.All the best mate
del /s *.txt will delete all TXT files in all subfolders of current working directory.
(But use that command carefully - wrong parent directory and you are throwing away all textfiles on your computer :) )
Edited
del /s d:\test\archive\*.txt
This should get you all of your text files
Alternatively,
I modified a script I already wrote to look for certain files to move them, this one should go and find files and delete them. It allows you to just choose to which folder by a selection screen.
Please test this on your system before using it though.
#echo off
Title DeleteFilesInSubfolderList
color 0A
SETLOCAL ENABLEDELAYEDEXPANSION
REM ---------------------------
REM *** EDIT VARIABLES BELOW ***
REM ---------------------------
set targetFolder=
REM targetFolder is the location you want to delete from
REM ---------------------------
REM *** DO NOT EDIT BELOW ***
REM ---------------------------
IF NOT DEFINED targetFolder echo.Please type in the full BASE Symform Offline Folder (I.E. U:\targetFolder)
IF NOT DEFINED targetFolder set /p targetFolder=:
cls
echo.Listing folders for: %targetFolder%\^*
echo.-------------------------------
set Index=1
for /d %%D in (%targetFolder%\*) do (
set "Subfolders[!Index!]=%%D"
set /a Index+=1
)
set /a UBound=Index-1
for /l %%i in (1,1,%UBound%) do echo. %%i. !Subfolders[%%i]!
:choiceloop
echo.-------------------------------
set /p Choice=Search for ERRORS in:
if "%Choice%"=="" goto chioceloop
if %Choice% LSS 1 goto choiceloop
if %Choice% GTR %UBound% goto choiceloop
set Subfolder=!Subfolders[%Choice%]!
goto start
:start
TITLE Delete Text Files - %Subfolder%
IF NOT EXIST %ERRPATH% goto notExist
IF EXIST %ERRPATH% echo.%ERRPATH% Exists - Beginning to test-delete files...
echo.Searching for .txt files...
pushd %ERRPATH%
for /r %%a in (*.txt) do (
echo "%%a" "%Subfolder%\%%~nxa"
)
popd
echo.
echo.
verIFy >nul
echo.Execute^?
choice /C:YNX /N /M "(Y)Yes or (N)No:"
IF '%ERRORLEVEL%'=='1' set question1=Y
IF '%ERRORLEVEL%'=='2' set question1=N
IF /I '%question1%'=='Y' goto execute
IF /I '%question1%'=='N' goto end
:execute
echo.%ERRPATH% Exists - Beginning to delete files...
echo.Searching for .txt files...
pushd %ERRPATH%
for /r %%a in (*.txt) do (
del "%%a" "%Subfolder%\%%~nxa"
)
popd
goto end
:end
echo.
echo.
echo.Finished deleting files from %subfolder%
pause
goto choiceloop
ENDLOCAL
exit
REM Created by Trevor Giannetti
REM An unpublished work
REM (October 2012)
If you change the
set targetFolder=
to the folder you want you won't get prompted for the folder.
*Remember when putting the base path in, the format does not include a '\' on the end.
e.g.
d:\test
c:\temp
Hope this helps