0

I am new with batch scripts. I made my script that allows me to search and backup all pictures on hard drive and copy them to usb flash but I have problem with hidden files. I want that my script can search and copy hidden pictures too. Now it don't copy hidden files or don't see them. Maybe someone will help me.

My script looks like this:

SET FileSizePic=10000

if not exist "%~d0\Backup\allPictures\" mkdir %~d0\Backup\allPictures

for /R "%UserProfile%" %%F in (*.jpg *.jpeg) do if %%~zF GTR %FileSizePic% (copy "%%F" "%~d0\Backup\allPictures\")
if exist D:\ for /R "D:\" %%F in (*.jpg *.jpeg) do if %%~zF GTR %FileSizePic% (copy "%%F" "%~d0\Backup\allPictures\")

pause
alzajac
  • 17
  • 4
  • 1
    CD/PushD into your base folder and then use `For /f "delims=" %%F in ('Dir /B/S/AH *.jpg *.jpeg') do if....` . For /R has no /A parameter to get defined Attributes. –  May 06 '17 at 17:42
  • I changed the code like this but it doesn't work. Maybe I understood you wrong. "C:\ESD\" is an example. 'SET FileSizePic=10000 if not exist "%~d0\VisualStudio\ArchitectureExplorer\allPictures\" mkdir %~d0\VisualStudio\ArchitectureExplorer\allPictures cd/pushd "C:\ESD\" for /f "delims=" %%F in ('Dir /B/S/AH *.jpg *.jpeg') do if %%~zF GTR %FileSizePic% (copy "%%F" "%~d0\VisualStudio\ArchitectureExplorer\allPictures\") pause' – alzajac May 07 '17 at 09:17
  • If you enter the dir cmd manually in the folder, what output do you get? –  May 07 '17 at 09:34
  • If I do it like this 'for /f "C:\ESD\" %%F in ('Dir /B/S/AH *.jpg *.jpeg') do if %%~zF GTR %FileSizePic% (copy "%%F" "%~d0\VisualStudio\ArchitectureExplorer\allPictures\")' the message is "C:\ESD" is unexpected at this time". When I put code like in my first answer to your comment the message was (after cd/pushd "C:\ESD\ ) : "name of file, directory or volume label syntax is incorrect". After loop was "file not found". – alzajac May 07 '17 at 10:13
  • That's not what I meant. First `cd C:\ESD` then `for /f "delims=" %%F ('Dir /b/s/ah .....` –  May 07 '17 at 10:20
  • Ok, now it's found a hiden picture but it didn't copy it. The message was: C:\ESD>if 1376892 GTR 10000 (copy "C:\ESD\DSC_0240.JPG" "D:\VisualStudio\ArchitectureExplorer\allPictures\" ) C:\ESD\DSC_0240.JPG File was not found. 0 file(s) copied. – alzajac May 07 '17 at 10:27
  • Ok, change copy to xcopy /h do the job! :) Thanks a lot for all help :) – alzajac May 07 '17 at 10:29
  • I said that to soon ;) Now I have another problem. I see that is working only to a specyfied directory (in this matter C:/ESD). It's not searching whole catalog in this directory or cannot copy files from subdirectories. I made a experiment and i made subdirectory "proba" in directory C:/ESD. I put there a copy of jpg file from C:/ESD. My script copied only jpg file from maid directory. A copy from C:/ESD/proba/ wasnt copy. – alzajac May 07 '17 at 11:18
  • Please read my first comment carefully. Looks like your base folder should be root. `Dir /B/S` will iterate through all subfolders starting from current folder. –  May 08 '17 at 16:47
  • Ok, thanks, now it''s all working good :) – alzajac May 09 '17 at 14:32

0 Answers0