0

I am able to get list of all the file names, path size etc using the below code but I have not been able to get rid of double quotes in the file name and file path. Also i have spaces in the file name that breaks when the file name is listed.

@echo off
setlocal enabledelayedexpansion



   if exist Z:\ (net use Z: /delete)
net use Z: "\\my drive path"
SET Path1=Z:\
pushd
SET "Path2=Z:\folder1"

for /f "skip=1 tokens=1,2,3,4,5* delims=,] " %%i in ('forfiles /p "%Path2%" /s /m ""*.mmp"" /c "cmd /c echo @fsize 0x22@file0x22 @path @fdate @ftime"') do (
set FILE_SIZE_WINDOWS=%%i
set FILE_NAME=%%~j
set FILE_PATH=%%~k
set FILE_DATE=%%l
set FILE_TIME=%%m
set "unit=B"
for %%b in (KB MB GB TB PB EB ZB YB) do if 1024 lss !FILE_SIZE_WINDOWS! (
set "unit=%%b"
if  !FILE_SIZE_WINDOWS! lss 2147483647 (set /a "FILE_SIZE_WINDOWS=FILE_SIZE_WINDOWS/1024") else (set "FILE_SIZE_WINDOWS=!FILE_SIZE_WINDOWS:~0,-3!"))
if "!FILE_NAME!" neq "!FILE_NAME:Admin=!" (set Developer=Admin
echo !Developer!) 
echo !FILE_NAME! !FILE_SIZE_WINDOWS!!unit! !FILE_PATH! !FILE_DATE! !FILE_TIME! !Developer!
if "!FILE_NAME!" == "!FILE_NAME:Undo=!" (echo !FILE_NAME! does not contain Undo
echo !FILE_NAME! !FILE_SIZE_WINDOWS!!unit! !FILE_PATH! !FILE_DATE! !FILE_TIME! !Developer! >> List.txt
) else (
echo !FILE_NAME! !FILE_SIZE_WINDOWS!!unit! !FILE_PATH! !FILE_DATE! !FILE_TIME! !Developer! >> UndoList2.txt
)
)
echo Done
popd
endlocal

Expected output:
Filename.mmp C:\Filepath
UserKD
  • 31
  • 1
  • 5
  • Double quotes in a filename? That's an interesting trick - please edit-in a `dir` listing of the filenames in question. – Magoo Jun 18 '19 at 22:23
  • In the `forfiles` command line, replace `0x22@file0x22` by `@file`. And why do you double-double-quote the mask `/m ""*.mmp""`? Anyway, I'd get rid of `forfiles` here and use a normal `for` loop with [`~` modifiers](https://ss64.com/nt/syntax-args.html) instead... – aschipfl Jun 18 '19 at 23:04
  • Possible duplicate of [List all file parameters in directory recursively using forfiles in for loop](https://stackoverflow.com/questions/56614812/list-all-file-parameters-in-directory-recursively-using-forfiles-in-for-loop) – Compo Jun 19 '19 at 00:19
  • Compo, I only asked that question but started separate thread so i can get rid of double quotes and display file names with spaces. – UserKD Jun 19 '19 at 01:36

0 Answers0