Go Back   Tech Support Forum > Microsoft Support > Windows XP Support

User Tag List

[SOLVED] Delete text from .txt file in a batch file

This is a discussion on [SOLVED] Delete text from .txt file in a batch file within the Windows XP Support forums, part of the Tech Support Forum category. Alright, so what I'm trying to do is list all the shortcuts & folders in the start menu and list


Closed Thread
 
Thread Tools Search this Thread
Old 04-07-2009, 07:51 AM   #1
Registered Member
 
Join Date: Mar 2009
Posts: 72
OS: XP



Alright, so what I'm trying to do is list all the shortcuts & folders in the start menu and list all the shortcuts & folders on the desktop and put this into a text file. The reason is to get a full list of programs our teachers use before we re-image their machine and not all of their programs are listed in add/remove programs and not all programs make a folder in Program Files, that is why I'm trying to do it in this roundabout way. What I have so far is this:

@echo off
mkdir "p:\Program List"
DIR "c:\documents and settings\all users\start menu\*" /S/B/OD > "p:\Program List\%computername% Start Menu.txt"
DIR "c:\documents and settings\all users\desktop\*" /S/B/OD > "p:\Program List\%computername% Desktop.txt"

This works perfectly but the only problem is the file has these:
c:\documents and settings\all users\start menu\
c:\documents and settings\all users\desktop\

before each entry in the text file. Is there an easy way to remove these lines so the text files are easier to read? I've checked other sources and can't figure out how to get this to work...
Ryan2065 is offline  
Sponsored Links
Advertisement
 
Old 04-07-2009, 08:45 AM   #2
CCT
Helper
 
CCT's Avatar
 
Join Date: Mar 2009
Posts: 4,126
OS: abacus



Open the files in Notepad, click Edit, then replace, and enter the string C:\Documents and Settings\All Users\ and replace it with nothing (no entry).

:)
CCT is offline  
Old 04-07-2009, 08:47 AM   #3
Registered Member
 
Join Date: Mar 2009
Posts: 72
OS: XP



Quote:
Originally Posted by CCT View Post
Open the files in Notepad, click Edit, then replace, and enter the string C:\Documents and Settings\All Users\ and replace it with nothing (no entry).

:)
Heh, so no batch file way to do it? Just last week I re-imaged 60 computers, so that wouldn't be worth it to go through one by one.

Though I never planned on deleting that text until I showed the other techs and they want it deleted... I think it is fine the way it is.
Ryan2065 is offline  
Sponsored Links
Advertisement
 
Old 04-07-2009, 09:38 AM   #4
CCT
Helper
 
CCT's Avatar
 
Join Date: Mar 2009
Posts: 4,126
OS: abacus



Well, if you copied the read only file Start Menu to the root C: and then did your other magic, the path name would be shorter.

:)
CCT is offline  
Old 04-07-2009, 11:52 AM   #5
Registered Member
 
Join Date: Mar 2009
Posts: 72
OS: XP



Hmm, is there a way to delete the first few characters of each line through a batch file?
Ryan2065 is offline  
Old 04-07-2009, 01:13 PM   #6
Registered Member
 
Join Date: Mar 2009
Posts: 72
OS: XP



I figured it out. I downloaded the gawk tool and ran this batch file:

xcopy /y c:\files\gawk.exe c:\windows\system32\

mkdir "p:\Program List"

DIR "c:\documents and settings\all users\start menu\*" /S/B/OD > "c:\temp1.txt"
DIR "c:\documents and settings\all users\desktop\*" /S/B/OD > "c:\temp2.txt"

type "c:\temp1.txt"|gawk '{printf"%%s\n",substr($0,48,255)}' > "c:\temp3.txt"
type "c:\temp2.txt"|gawk '{printf"%%s\n",substr($0,44,255)}' > "c:\temp4.txt"

copy c:\files\backup1.txt+c:\temp3.txt+c:\files\backup2.txt+c:\temp4.txt "p:\Program List\%computername%.txt

del c:\temp1.txt
del c:\temp2.txt
del c:\temp3.txt
del c:\temp4.txt

Just for reference, the backup1.txt and backup2.txt files are just a few lines of blank text and a header to space out the start menu data and the desktop data.

I'll mark this one as solved.
Ryan2065 is offline  
Old 04-07-2009, 02:20 PM   #7
TSF Enthusiast
 
Squashman's Avatar
 
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,645
OS: All of the above



You way over thought this one.

You could have just done this.
Code:
cd "c:\documents and settings\all users\start menu"
dir /s/b/od > "p:\Program List\%computername% Start Menu.txt"
cd "c:\documents and settings\all users\desktop"
DIR /S/B/OD > "p:\Program List\%computername% Desktop.txt"
Squashman is offline  
Old 04-07-2009, 02:23 PM   #8
TSF Enthusiast
 
Squashman's Avatar
 
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,645
OS: All of the above



Quote:
Originally Posted by Ryan2065 View Post
Hmm, is there a way to delete the first few characters of each line through a batch file?
Yes and there is alot easier way to do it then what you did without having to use a 3rd party utility. You can do it natively with batch commands.
Squashman is offline  
Old 04-07-2009, 02:27 PM   #9
TSF Enthusiast
 
Squashman's Avatar
 
Join Date: Apr 2005
Location: 1265 Lombardi Ave.
Posts: 1,645
OS: All of the above



You probably should have checked this as well.
C:\Documents and Settings\%USERNAME%\Start Menu
C:\Documents and Settings\%USERNAME%\Desktop
Squashman is offline  
Old 04-07-2009, 02:51 PM   #10
Microsoft MVP
 
TheOutcaste's Avatar

Microsoft Most Valuable Professional
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 3,339
OS: MS-Dos 6.22 - Win7



This would have created the files without the path present
Code:
@echo off
mkdir "p:\Program List"
PushD %allusersprofile%\start menu
DIR *.* /S/B/OD > "p:\Program List\%computername% Start Menu.txt"
PopD
PushD %allusersprofile%\desktop
DIR *.* /S/B/OD > "p:\Program List\%computername% Desktop.txt"
PopD
I would use DIR *.lnk /S/B/OD /A-D instead to list only shortcuts and to not output folder names.
Also, this will only list the items in the all users profile. The users may have shortcuts that exist only in their profile, so you should also do the following to be complete:
Code:
@echo off
mkdir "p:\Program List"
PushD %allusersprofile%\start menu
DIR *.* /S/B/OD > "p:\Program List\%computername% All Start Menu.txt"
PopD
PushD %allusersprofile%\desktop
DIR *.* /S/B/OD > "p:\Program List\%computername% All Desktop.txt"
PopD
PushD %userprofile%\start menu
DIR *.* /S/B/OD > "p:\Program List\%computername% %username% Start Menu.txt"
PopD
PushD %userprofile%\desktop
DIR *.* /S/B/OD > "p:\Program List\%computername% %username% Desktop.txt"
PopD
If there are more than one user account on each PC, the last section would need to be run while logged into each profile. Or have the batch file enumerate all the profiles and do each one.


This would remove the leading path after the files are created. One glitch, if any of the shortcuts use &,%, or ! in their name, that will cause a problem.
Code:
@echo off
Setlocal EnableDelayedExpansion
PushD p:\Program List\
For /F "Tokens=*" %%A In ('Dir /B /A-D "*Start Menu.txt"') Do (
  For /F "tokens=*" %%I In ('type "%%A"') Do (
    Set _text=%%I
    >>"%%~dpnA.tmp" Echo.!_text:~47!
    )
  Del "%%A"
  Ren "%%~dpnA.tmp" "%%A"
)
For /F "Tokens=*" %%A In ('Dir /B /A-D "*Desktop.txt"') Do (
  For /F "tokens=*" %%I In ('type "%%A"') Do (
    Set _text=%%I
    >>"%%~dpnA.tmp" Echo.!_text:~44!
    )
  Del "%%A"
  Ren "%%~dpnA.tmp" "%%A"
)
PopD
HTH

Jerry
TheOutcaste is offline  
Old 04-08-2009, 06:07 AM   #11
Registered Member
 
Join Date: Mar 2009
Posts: 72
OS: XP



Quote:
Originally Posted by Squashman View Post
You way over thought this one.
Heh, I do that alot.

Thanks TheOutcaste, I ended up using your last script instead of the gawk.exe tool and changed some other things around (used copy to merge the two text files into one).

Thanks for all the help guys!
Ryan2065 is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2
Powered by vBadvanced CMPS v3.2.3


All times are GMT -7. The time now is 06:55 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
vBulletin Security provided by vBSecurity v2.2.2 (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.1.0 (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
Copyright 2001 - 2018, Tech Support Forum

Windows 10 - Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts