Create Spreadsheet in Excel of Name and File Type Using Script - excel

I have a bunch of excel files and other types of files that I need to populate into a spreadsheet to keep track of them. I was what the batch script would look like for such task. Also I want to be able to pin point which folders I want to get the file names from.
Thanks in advance

Dir does do multiple folders.
dir c:\windows "c:\program files\e*.txt" /a
Here's doing My Docs.
for /f "skip=2 tokens=3" %A in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Personal"') do set doc=%A
for /f "usebackq tokens=2* delims= " %i IN (`dir "%doc%" /a /s ^|findstr /i /v "\/"^|findstr /l /v "Pictures Music Video"`) DO #echo %j&echo.

Related

How to loop through a directory and skip folders containing a specific string?

I am currently scanning an entire directory, copying an exe over and running it in each folder. This exe converts certain log files within each folder. However, half the directories don't contain any log files and it seems like a waste to move into each of those folders and run an exe that does nothing. An example of some folder names:
0075D-S10
0075D-S10-EVT
0132C-S10
0132C-S10-EVT
and so on...
I basically only need to copy the executable into the folders that don't contain EVT in the name. These just contain evtx files that aren't important to me at the moment.
Here is a snippet of my batch file and what it is doing:
set back=%cd%
set current_dir=%cd%
setlocal EnableDelayedExpansion
for /d %%i in ("%current_dir%\*") do (
copy LogCsv.exe "%%i" >NULL
cd "%%i"
LogCsv.exe
)
cd %back%
Really my first time just using Batch files and I've been exploring answers on here, but couldn't find a solution to this particular problem. How can I loop this directory, excluding any folders containing the "EVT" string in their name?
Thanks for taking time to assist!
Well, you can use findstr /v to exclude certain values from search results.
#echo off
set back=%cd%
set current_dir=%cd%
for /f %%i in ('dir /b /ad %current_dir%\* ^| findstr /v EVT') do (
copy LogCsv.exe "%%i" >NUL
cd "%%i"
LogCsv.exe
cd %back%
)
Also note, you need to pipe to nul not null

Batch Scripting - Search for value in text file and copy word next to it

Currently writing a batch program but I seem to be having a difficult time with string manipulation. I need help scanning through the contents of the Output.txt file below, in search of the the word ssudmdm. wherever the word is found, i then need to retrieve the com value on the same line, to the right and store it in a variable.
I am aware that there are a few examples on the site, however I have have tried implementing them with no luck. Any help would be appreciated.
Code:-----------------------------------------------
#ECHO OFF
:: Use local environment copy
SETLOCAL
::regedit.exe /S VM_Putty_Settings.reg
:while1
reg QUERY "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM" > Output.txt
#start /wait FIND /C /I "ssudmdm" Output.txt
if %ERRORLEVEL% == 1 (
timeout /t 2 >nul
goto :while1
)
for /f "tokens=3" %%a in ('find /i "ssudmdm" output.txt') do set var=%%a
reg add "HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\VM_Putty_Settings" /V SerialLine /T REG_SZ /D "%var%" /F
pause
start Putty.exe -load VM_Putty_Settings < nul >NUL 2>NUL
ENDLOCAL
GOTO:EOF
Output file----------------------------------
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
\Device\Serial0 REG_SZ COM1
\Device\Serial1 REG_SZ COM2
\Device\ssudserd0000 REG_SZ COM5
\Device\ssudserd0001 REG_SZ COM6
\Device\ssudmdm0000 REG_SZ COM7
Here's how to do it all in one statement, without your intermediate file.
for /f "skip=2 tokens=3" %%a in ('reg query hklm\hardware\devicemap\serialcomm /v *ssudmdm* ^| find /i /v "end of search"') do set var=%%a
If you must have the intermediate file for some reason:
for /f "tokens=3" %%a in ('find /i "ssudmdm" output.txt') do set var=%%a

Search specified directory and output location of item(s) if found

Like the title says, I would like to know how to search a specified directory for a specified file using a for loop in a windows batch script. I can't use any 3rd party software.
Heres what I have at the moment:
for /R "%loc%" %%f in ("%searchterm%") do (
echo %%f
echo %%f>> "%genloc%wefound.txt"
)
%loc% is the location in which it should search.
%searchterm% is the file (e.g "hello.txt") that the script much search for.
It must output any files found (including their full path) on the screen and into the wefound.txt.
Let me know if you need more detail.
for /f "delims=" %%f in ('dir /s /b /a-d "%loc%\%searchterm%"') do (
echo %%f
echo %%f>> "%genloc%wefound.txt"
)
To get the for /r command recursively enumerate the files under a starting point, the file set must include some wildcard character (* or ?). As you know the exact filename, let the dir command do the work of searching the file.
for /R "%loc%" %%f in ("%searchterm%") do (
echo %%~Ff
echo %%~Ff>> "%genloc%wefound.txt"
)
For further details, type: FOR /?
Why complicate things with FOR? All you need is the DIR command:
dir /s /b /a-d "%loc%\%searchterm%>"%genloc%wefound.txt"&type "%genloc%wefound.txt"
The solution is even better if you can get your hands on a Windows port of the tee command (there are numerous free versions available). You could use my hybrid JScript/batch implementation of tee
dir /s /b /a-d "%loc%\%searchterm%"|tee "%genloc%wefound.txt"

Batch file to search files in a folder

I need a bat file to search excel files in a folder. It should do the following
search in a folder
looks for excel files after created date
if it is older than system date deletes the excel file
if not it runs a converter.js
Can any one help.
Here you go. Remove the echo's from the script once you see good output on the screen. Also, I'm not sure how you are running converter.js so you'll need to change that line to however you do it and if your file dates are in a different format, you'll have to re-arrange the "%MM%/%DD%/%YYYY%" too.
#echo off
setlocal enabledelayedexpansion
pushd "C:\location\of\files\"
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
for /f "tokens=*" %%a in ('dir /o-d /b /tc *.xls') do (
for /f "tokens=1" %%b in ("%%~ta") do (
if "%%b" NEQ "%MM%/%DD%/%YYYY%" (
echo del "%%a"
) ELSE (
echo run converter.js
)
)
)
popd

Is it possible rename all files in a directory to 0.jpg, 1.jpg, 2.jpg, etc?

I have a bunch of images (100+) in a directory, all with different names. Is there any way to rename them, possibly with a script (I'm running Windows), to 0.jpg, 1.jpg, 2.jpg, etc... without having to rename each one individually? I could launch a Linux virtual machine and copy them over if it isn't possible in Windows.
I've got this so far
#echo off
setlocal enableDelayedExpansion
set MYDIR=F:\Pictures\Wallpapers
set /a count = 0
for /F %%x in ('dir /B/D %MYDIR%') do (
echo %%x
#echo !count!
set /a count+=1
)
Which display the correct file name and the correct counter, but when I try
ren %%x !count!.jpg
Tells me "The system could not find the file specified."
You are not providing the full path for the source file. Don't forget that %%x is just the file name; you need to prepend %MYDIR% to have a complete path:
ren %MYDIR%\%%x !count!.jpg

Resources