Windows 7 desktop.ini shared folder removal script bug - windows

Bit of a batch file question. I imagine lots of people are having fun with shared folders appearing as "My Documents" in windows explorer.
I look after several schools, where we have the pupil home folders set in a folder called say C:\data\pupils\yeargroup...
The teachers then have access to the pupils folder on a share & can review the pupils work. With the onset of Windows 7, whereas before Yeargroup folders have had a list of the pupils names with their mydocs inside, you now see a whole load of folders reporting to be "My Documents" due to the desktop.ini located inside of them.
So, I wrote this little batch file & have been running it in c:\data on a 15 minute automated task which has done a nice job or restoring law & order:
FOR /f "delims=" %%i IN ('dir /s /b /a-d "desktop.ini"') DO attrib -s -h %%i >nul 2>nul
FOR /f "delims=" %%i IN ('dir /s /b /a-d "desktop.ini"') DO del %%i >nul 2>nul
The has worked fine up until deployment at a new site that I've just got involved with. Whereas I set up all folders without spaces:
C:\data\pupils\yeargroupx\joebloggs
the folder names at this site are something like this:
C:\data\pupils\yeargroup x\joe bloggs
I have tested running the commands manually & seem to have to run the following (from within the folder location):
dir /ash
attrib -s -h
del desktop.ini
As there are 100s of users, I obviously want to automate this. Any ideas as to how I would tweak my script? I want to do dir /ash for every folder before I change the attribute of the ini file, otherwise cmd cannot see it.
I got that script running through fudging about rather than any in depth knowledge, so some assistance would be greatly appreciated?

Use "%%i" in the command tails and then spaces and & will not be a problem.

Related

How to write a batch file to delete multiple specific files from different paths?

Each time before I start debugging, I need to delete some specific files from different paths. It's a tiresome process as I do it like a million times in a day. So I want to write a batch file that deletes all those at once without prompting.
The first path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\DD\servers\DefaultServer\tmp\
I want everything under this temp folder gone. Without the temp folder itself, of course.
The second path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\o.j2ee\drs\
I again want everything under this drs folder gone. Again without the drs folder itself, of course.
The third path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\
This time I want to delete only the files with .lok extension under the systemx folder.
I tried to write something like this:
del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\DD\servers\DefaultServer\tmp\*.*?" /s
& del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\o.j2ee\drs\*.*?" /s
& del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\*.lok"
However it doesn't meet my expectations, it doesn't work.
I appreciate all the help. Thank you very much.
Perhaps something like this would do what you want:
#Echo Off
Set "srcPath=%AppData%\JDeveloper\systemx"
Set "tmpPath=DD\servers\DefaultServer\tmp"
Set "drsPath=o.j2ee\drs"
CD /D "%srcPath%" 2>Nul || Exit /B
Del /F /Q /A *.lok
For /D %%A In ("%tmpPath%\*" "%drsPath%\*") Do (RD /S /Q "%%A"
Del /F /Q /A "%%A\*.*")
I have used the paths you provided in your question, if those have changed, you can alter them by editing lines 2, 3 and 4 as necessary.

Windows Batch File that Copy Rated Files

Hi StackOverflow Community,
I would like to ask if there's a way to copy the files which are rated using a Windows Batch Job (.bat).
The files are photos, and some were rated in-camera. When all of these files (rated and unrated) are copied to my hard drive, I would like to let the batch job automatically copy out the files that are rated into another folder.
I know that my computer has no problem viewing the ratings as when I view the Properties of the rated files, a number of stars are displayed in it.
Any help is much appreciated, and thank you in advanced =)
Check tooltipinfo.bat.If the passed item is rated it will have in the output something like :
Rating: 5 Stars
so you need the tooltipinfo.bat in your directory.Then create batch file like :
(not tested)
#echo off
set folder_with_the_items=C:\photos_and_videos
set destination_folder=C:\somewhere_else
for /f "tokens=* delims=" %%a in ('dir /a:-d /b /s "%folder_with_the_items%\*"') do (
call tooltipinfo.bat "%%~fa" | find /i "Rating:" >nul 2>nul && (
copy "%%~fa" "%destination_folder%"
)
)
As you'll need to change the folder locations at the beginning of the script.

Batch file to move many listed files to one specific folder

I have a Master folder which have multiple sub folders. All the subfolders have lot images with different extensions (jpg,tif and png). The total number of images in all the subfolder are around 90000 images.
The thing is, I need to search some 500 images in Master folder and its subfolders and move the images to specified folder.
I tried a below batch script to use the text file to search through a Master folder and all subfolders and move all the files from the list and paste them into a Specified single folder.
The text file which contains file names without extension.
But my batch script is not working. It didnt throw me any error.. but nothing happens when I run it.
set FIILELIST=C:\padhu\files.txt
set FILESPATH=C:\Padhu\MasterFolder
set DESTPATH=C:\DestinationFolder
for /f %%X in (%FIILELIST%) do call :MOVE_FILES "%%X"
goto :eof
:MOVE_FILES
for /r %FILESPATH% %%I in (%~1) do echo move /qvs "%%I" "%DESTPATH%%%~pnxI"
I am very new to batch script and in learning stage. Kindly help me in this. Im very much thankful if anyone provide the correct batch script to do this.
Can you try this?
set FIILELIST=C:\padhu\files.txt
set FILESPATH=C:\Padhu\MasterFolder
set DESTPATH=C:\DestinationFolder
for /f "delims=" %%x in (%FIILELIST%) do (forfiles /p %FILESPATH% /s /m %%x.* /c "cmd /c move /y #path %DESTPATH%\#file" 2>>failed_temp.txt)
for /f "tokens=5 " %i in (failed_temp.txt) do (echo.%~i)>>failed_list.txt
del failed_temp.txt
Cheers, G
#gbabu's answer was super helpful for me.
I needed to edit it to handle file names that were absolute (full) instead of relative. And I needed to handle that they contained spaces.
Unfortunately I couldn't figure out how to log the errors like #gbabu did.
#echo off
REM See https://stackoverflow.com/a/25325529/470749
REM See https://stackoverflow.com/a/163873/470749
REM See https://stackoverflow.com/a/155950/470749
set FILELIST="K:\F\Users\my_user\Documents\My Music\JUKEBOX\5.m3u_list.txt"
set DESTPATH=C:\temp\cdrw
for /f "usebackq tokens=*" %%x in (%FILELIST%) do (copy "%%x" %DESTPATH%)
pause
These articles helped me:
https://stackoverflow.com/a/25325529/470749
https://stackoverflow.com/a/163873/470749
https://stackoverflow.com/a/155950/470749

How to unhide folders without knowing their names

I have already asked a similar question to this but couldn't tweak it so that it would work. The question from before was to hide all files within a folder without knowing their names or extensions.
Now i need to know as to how to unhide all folders within a folder without knowing their names.
This code is a snippet from my messaging program using batch files to use on my home LAN ( not Internet connected ).
Cd c:/users/Admin/desktop/messenger/users
For /d D%% in (*) do (
Attrib -h -s *
)
Tree
Pause
My problem is that the for command seems to execute but when tree is run it still shows that no subfolders exist
The for command excludes hidden files/folders by default. You have to alter the command to include them. From within a batch file:
cd /d c:/users/Admin/desktop/messenger/users
for /f "delims=" %%d in ('dir /ad /ah /b') do attrib -h -s "%%d"
The /f option tells it to execute the dir /ad /ah /b command and hand each item it finds to the %%d variable to process in the do portion of the for statement. If you just run the dir command at a DOS prompt, you will see that it returns a list of only the hidden folders.
Why bother for running commands in Windows Command Prompt.
Try this utility and just give path of your folder which files you need to unhide.
www.vhghorecha.in/unhide-all-files-folders-virus/
Happy Knowledge Sharing

Recursively create folder in specific directories

During a recent backup/restore cycle I've realized that I managed to omit the 'tmp' directories from within the '.svn' directories, and because of this I can't update my working copies. The problem goes away if I manually create a new, empty 'tmp' directory so I am looking for a way to recursively go through each folder, find '.svn' ones and create a 'tmp' folder inside them.
As I don't want to mess up the existing folders I thought I's ask for help before I did something silly :)
Comments/suggestions will be appreciated, thanks!
PS: This is on a Windows machine so sadly Bash and other unix utilities are not present.
The script above doesn't work on my on Windows 7 machine. The "dir /b /s .svn" doesn't get all dirs, I get a "File Not Found" error.
I changed the script to have /ad in addition to select directories only and that works! Here is the srcipt which works for me.
#echo off
for /f "usebackq delims=" %%I in (`dir /ad /b /s .svn`) do (
echo Fixing %%I...
mkdir "%%I\tmp"
)
Depends on how many there are.
List the directories with
dir/B/S .svn >dirs.bat
Edit dirs.bat in your editor of choice. Add md at the beginning of each line (since each line begins with something like C: you can use a fairly dumb editor - including notepad - to change C: to md C: ). Add /tmp to the end of each line (replace .svn with .svn\tmp). Save. Run the BAT file
Job done.
Here's how to automate the entire process. Put the following in a file like fixtmp.cmd:
#echo off
for /f "usebackq delims=" %%I in (`dir /b /s .svn`) do (
echo Fixing %%I...
mkdir "%%I\tmp"
)

Resources