I want to find the .seq files from src folder and its sub-directories. I'm trying with below approach but it doesn't create a devtest.txt file. Any help please.
For /R %%A In (src\*.seq)Do #Echo drafting.rep:%%~nxA >> devtest.txt
A FOR loop will find all of the files and run the ECHO command on them.
#SET "SEARCHDIR=C:\src"
#SET "LOGFILE=%USERPROFILE%\devtest.txt"
#IF EXIST "%LOGFILE%" (#DEL "%LOGFILE%")
#FOR /F "delims=" %%A IN ('DIR /S /B "%SEARCHDIR%\*.seq"') DO (
#Echo drafting.rep:%%~nxA >>"%LOGFILE%"
)
Related
I need to make batch script, which will work this way:
There is a folder with one hundred files. I need to make a script which is zipping every 4 files into single archive. Then all created archives must be zipped into one, big archive file. That must be all done by one script.
I tried to make it, but I haven't idea how to make it this way.
This is what I wrote first:
#ECHO ON
SET SourceDir=C:\Users\Ridaan\Documents\sobol
SET DestDir=C:\folder\Destination
CD /D "C:\Program Files\7-Zip"
FOR /F "TOKENS=*" %%F IN ('DIR /B /A-D "%SourceDir%"') DO (
7z.exe a "%DestDir%\%%~NF.zip" "%SourceDir%\%%~NXF"
)
EXIT
And second:
#echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
robocopy C:\folder\Destination /COPY:DAT /V /XO /NJH /NP /R:1000 /W:10
7z u -mx9 "C:\folder\End.7z" "C:\folder\Destination"
rmdir C:\folder\End\ /Q /S
:END
pause
Just to give you an idea of counting files and
calculating the int of count/4 for the zip number
the modulus%4 for the file number (0..3) to determine if it's a new zip to create or to append to the zip.
:: Q:\Test\2018\11\11\SO_53251220.cmd
#Echo off&SetLocal EnableExtensions EnableDelayedExpansion
set Cnt=0
Set "SrcDir=X:\Your\Path"
For /F "delims=" %%A in ('Dir /B/A-D "%SrcDir%\*"') do (
Set /A "File=Cnt%%4,Zip=Cnt/4,Cnt+=1"
Echo Cnt=!Cnt! File=!File! Zip=!Zip! File=%%A
)
I am traversing folders on a drive, collecting file names with specific extensions, and building a string which is later used in a command line switch. When I find a qualifying file I need to know its full path as this is what is required by the command line. I currently use "%~dp0%%a\%%b" to build the full path, but I can see that may have limitations later on when the batch becomes more complex (e.g. it digs deeper into sub folders). I am hoping there is a way to replace "%~dp0%%a\%%b" with the path to the located file. Thank you:
#ECHO OFF
for /f "usebackq tokens=*" %%a in (`dir /b /a:d`) do (
pushd %%a
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%b in ('dir /b "*.E01" "*.L01" "*.AD1" 2^>nul') do (
SET EVIDENCE_STR=!EVIDENCE_STR! /e:"%~dp0%%a\%%b"
)
IF DEFINED EVIDENCE_STR (
ECHO !EVIDENCE_STR!
) ELSE (
ECHO No evidence files located in: %%a
)
endlocal
SET EVIDENCE_STR=
popd
)
PAUSE
Why do you need to create 2 loops, each running a dir command to find files? Why not just do for /R loop? Here is an example:
#echo off
set "files=*.E01 *.L01 *.AD"
for /R %%a in (%files%) do echo %%a
Simply use "Sub"-Option: /S of the DIR-Command:
Dir /B /S C:\*.jpg
cause it is that equivalent to:
#echo off
set "DirPath=C:\"
set "files=*.jpg"
for /R %DirPath% %%a in (%files%) do echo %%a
and so you should got the same result in each script.
The Problem: If you don't want any deep of SubDirectorys, you've to filter out these and so you may lose time - in both solutions.
This batch script creates a text file of a list of files in its own directory, sans file extensions. However, I would like it to create a list of another directory's files instead. How could I modify it to attain those results?
#echo off
cd %1
if exist filelisting.txt del filelisting.txt
for /F "delims=" %%j in ('dir /A-D /B /O:GEN') do echo %%~nj >> filelisting.txt
Nevermind, I figured it out:
#echo off
cd %1
if exist filelisting.txt del filelisting.txt
for /F "delims=" %%j in ('dir "c:\Location\*" /A-D /B /O:GEN') do echo %%~nj >> filelisting.txt
I have a need for a batch file or utility that would be able to find any "un-compressed archive folders" that are no longer needed and can now be deleted because the original archive file is still present.
The key is that the "un-compressed folder" and the "original archive file" always have the same name except for the file extension of the archive file. I do not want to automatically delete anything; I just want to create a list of folders that I can manually check out. So the sequence would be a 4 step process:
1) Search for all archive files using wildcards such as *.zip, *.rar, *.iso
2) Create a list of all of the filenames that are found - minus the file extensions
3) Use the list created in step two to search for any folders with those names
4) Create a text file with any folders found in step three.
I tried modifying a batch file that I found in these posts but it didn't work and I would like to start from scratch. Any help would be greatly appreciated.
Thanks
Ok, I'll do this step by step:
Step 1:
set dir="C:\...[path to root directory]"
where /r %dir% *.zip *.iso *.rar >> log.txt
Note the where utility should be on your computer if using windows 7.
Step 2:
ren log.txt log.tmp
for /f "delims=." %%a in (log.tmp) do (Echo %%a >> log.txt)
del log.tmp
The above code will not handle files names with periods in it
Step 3:
for /f "tokens=*" %%a in (log.txt) do (
where /r %dir% %%a* >> files.txt
)
Not 100% sure if above will work, tell me if it doesn't.
Step 4:
Rem This code will handle file paths to directories
Ren files.txt files.tmp
for /f "tokens=*" %%a in (files.tmp) do (
Echo %%~pa >> files.txt
)
del files.tmp
Rem The below code will ged rid of repeated direcotries
ren files.txt files.tmp
Echo. > files.txt
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (files.tmp) do (
set var=1
for /f "tokens=*" %%b in (files.txt) do (
if "%%~a" equ "%%~b" set var=0
)
if !var!==1 Echo %%a >> files.txt
)
del files.tmp
And I'm rather confident that should work. Of course I haven't tested this, but run all of this with #Echo on and a pause command between each sect (or as seperate batch files) so that if an eror does occur I can try helping you.
Hope this was helpful, Mona.
#echo off
setlocal enableextensions
set "rootDir=d:\_data_"
set "fileList=%~dp0\%~n0.files.list"
set "folderList=%~dp0\%~n0.folders.list"
rem generate list of compressed files names
break > "%fileList%"
for /F "tokens=*" %%f in ('where /r "%rootDir%" *.zip *.rar *.iso *.7z 2^>nul') do (
>> "%fileList%" echo %%~nf
)
rem check compressed file list against directory list
break > "%folderList%"
for /F "tokens=*" %%f in ('dir "%rootDir%" /s /b /ad ^| findstr /e /g:"%fileList%" ') do (
>> "%folderList%" echo %%f
)
type "%folderList%"
endlocal
I have a .bat file written that creates a text file within each sub-folder of the root folder that displays the sub-folder's contents. The issue I'm having now is creating a second .bat that will remove said text files from the sub-folder locations. The .bat I have for creating the .txt files are located below. Any help is greatly appreciated!
#echo off
IF EXIST "R:\Projects\000" PUSHD "R:\Projects\000\"
FOR /F "tokens=*" %%G in ('dir /a:d-s-h /b') do (
dir /s/b > R:\Projects\000\%%G\Folder_Contents.txt
)
POPD
It's nearly the same as your current script.
delAllFolderContent.bat
#ECHO OFF
IF EXIST "R:\Projects\000" (
PUSHD "R:\Projects\000"
FOR /F "tokens=*" %%G in ('dir /a:d-s-h /b') DO (
DEL "R:\Projects\000\%%G\Folder_Contents.txt"
)
POPD
)
I moved the FOR/F code into the IF EXIST block, so it will be executed only when the directory exists and not always.
If i truly understand you. It's look like this:
#ECHO OFF
IF EXIST "C:\Temp\" PUSHD "C:\Temp\"
ECHO #ECHO OFF > loc.bat
FOR /F "tokens=*" %%G in ('dir /a:d-s-h /b') DO (
DIR /s/b > C:\Temp\%%G\Folder_Contents.txt
ECHO DEL C:\Temp\%%G\Folder_Contents.txt >> loc.bat
)
POPD
del "R:\Projects\000\folder_contents.txt" /s