Script wriring help (Attn: Pyprohly)


  1. Posts : 3
    Windows 7 Pro 64bit
       #1

    Script wriring help (Attn: Pyprohly)


    Hello,

    I found the below script on this very website (Folders & Shortcuts Losing Custom Icons On Removable Flash Drive) written by user Pyprohly. I am in the exact same situation as the person that originally posted, however there is one small piece of it that I am having trouble with.


    I have a portable hard drive with a bunch of video files on it. When I create custom folder icons for each video, they are fine until I take the hard drive to a different PC and plug it in. Thru the above mentioned thread, I was able to determine that the problem was with the desktop.ini file listing the drive letter in the path to the icon file. If you edit the desktop.ini file and remove (In my case) the I: part of the path, it no longer matters what drive letter the various PC's assign and the icon files work as I want them to.

    The problem I am having is that when I use the script in the above thread the script works perfectly if you have the files_named_like_this. If you have the file named without the underscores say for example "Jims Hockey Game" the script appears to be only using the last word in the title when it tries to write the file back into the folder. The script fails saying that the path was not found (in this example it would show that it was looking for the “I:\Game” path). This error happens to every folder that has a title with spaces in it. If the folder happens to only have a single word in the title, the script works fine and renames the .ini file.

    Would someone happen to know how to edit this script to have it work correctly with files that have spaces between the words in the folder title?


    I have attached a picture of what the error looks like when I run the script and I also have attached the script that is in the above link.


    Thank you for any help that can be provided.
    Attached Thumbnails Attached Thumbnails Script wriring help (Attn: Pyprohly)-example.jpg  
    Script wriring help (Attn: Pyprohly) Attached Files
      My Computer


  2. Posts : 6,285
    Windows 10 Pro X64
       #2

    Try sending Pyprohly a PM (Private Message).

    Edit: I see you are a new user so you will not be able to send a PM yet. I sent one for you.
      My Computer


  3. Posts : 3
    Windows 7 Pro 64bit
    Thread Starter
       #3

    LOL, thanks. I searched for 15 minutes last night looking for the PM feature. I thought I was going crazy.

    Thank you for forwarding that for me.
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    Hey, sorry for any delay,

    Thank you, PepFontana, for raising the error to my attention. That thread you mention, I think, was probably the third or so thread I ever assisted to here at Seven Forums. So I wouldn't be surprised if that batch script is riddled with other kinds of issues.


    I rewrote a new batch script, from ground up, which may help you with your issue, PepFontana.



    Find_And_Replace_Text.bat
    Code:
    @echo off
    setlocal EnableDelayedExpansion
    
    ::
    set find="F:"
    set replace=""
    set case_sensitive=TRUE
    set line_must_start_with="IconResource",
    ::
    set filemasks="desktop.ini",
    set recurse=TRUE
    set write_attributes=TRUE
    ::
    
    pushd "%~dp0"& echo.
    set tempfile="%TEMP%\tmp%RANDOM%_%~nx0.txt"
    if /i %RECURSE%==TRUE set recurse_=/s
    if /i %CASE_SENSITIVE%==TRUE ( set case_sensitive_=) else ( set case_sensitive_=/i)
    if /i %WRITE_ATTRIBUTES%==TRUE ( set write_attributes_=) else ( set write_attributes_=REM )
    for /f "delims=" %%I in (' dir /a:-d /b %RECURSE_% %FILEMASKS% ') do (
    	set/p=Processing "%%~fI"... <NUL
    	%WRITE_ATTRIBUTES_% attrib "%%~fI" -r -s -h
    	copy NUL "%TEMPFILE:"=%" /y >NUL
    	for /f "tokens=1,* delims=]" %%L in (' find /n /v "" ^< "%%~fI" ') do (
    		if not "%%~M"=="" for %%P in ( %LINE_MUST_START_WITH% ) do (
    			set line=%%M& echo.%%M| findstr /i "^%%~P" >NUL && (
    				if /i %CASE_SENSITIVE%==TRUE (
    					echo.%%M| findstr "%FIND:"=%" >NUL && (
    						set line=!LINE:%FIND:"=%=%REPLACE:"=%!
    					)
    				) else ( set line=!LINE:%FIND:"=%=%REPLACE:"=%!)
    			)
    		) else ( set line=)
    		echo.!LINE!>>"%TEMPFILE:"=%"
    	)
    	copy "%TEMPFILE:"=%" "%%~fI" /y >NUL
    	%WRITE_ATTRIBUTES_% attrib "%%~fI" +s +h
    	del "%TEMPFILE:"=%" /f /q
    	echo Done.
    )
    echo.& echo Complete.
    popd
    Script wriring help (Attn: Pyprohly) Attached Files
    Last edited by Pyprohly; 24 May 2015 at 09:34. Reason: Cut down on a few bytes in batch script.
      My Computer


  5. Posts : 3
    Windows 7 Pro 64bit
    Thread Starter
       #5

    Outstanding!! It works perfectly.

    Thank you so, so much.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:42.
Find Us