Mac convert this batch file into an applescript?

Icefire817

macrumors newbie
Original poster
Mar 26, 2011
13
0
WA
Hey, since you guys seem to know infinitely more about scripting than I do, could someone help me convert this batch file into an applescript?

for /F "tokens=*" %%a in (dupefilelist.txt) DO DEL "%%a"
for /F "tokens=*" %%a in (dupefolderlist.txt) DO rmdir "%%a" /S /Q

DEL dupefilelist.txt
DEL dupefolderlist.txt

Attrib -r
DEL %0

I felt that it went along w/ this thread....
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
I don't know about doing this in AppleScript, but this is an easy shell script to write.

Code:
cat dupefilelist.txt | xargs rm
cat dupefolderlist.txt | xargs rm -rf

rm dupefilelist.txt
rm dupefodlerlist.txt

chmod 755 $0
rm $0
(BTW Dup is short for duplicate. Dupe means "to trick or deceived". For example, "Did this guy dupe me into doing his work for him?")
 
Last edited:
Comment

Icefire817

macrumors newbie
Original poster
Mar 26, 2011
13
0
WA
Well, the shell script itself works but it keeps telling me that no such file or directory exists. I had to change the script to incorporate directories of the two duplicate list files but now i just don't know where to go from here.
 
Comment

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Well, the shell script itself works but it keeps telling me that no such file or directory exists.
Is that because you don't want have both dupefilelist.txt and dupefolderlist.txt, or is it because these lists include files/folders that don't exist?
 
Comment

Icefire817

macrumors newbie
Original poster
Mar 26, 2011
13
0
WA
both exist, but it doesn't seem to recognize that they do or it doesn't recognize the file path (which would take more time than I have to change)
 
Comment

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
both exist, but it doesn't seem to recognize that they do or it doesn't recognize the file path (which would take more time than I have to change)
This script (as does the batch file) assumes dupefilelist.txt and dupefolderlist.txt are in the current working directory.

Note that there is an important difference between Windows and Mac OS X with regards to starting a shell script by double-clicking its icon. Under Windows, the current working directory will be set to the directory of the script. Under Mac OS X, the current working directory is your home directory.

To be safe, put a cd command at the top of the script.

For example, if the *.txt files and the files and folders to be deleted where all in ~/Movies, then put this cd command the start of the script.

Code:
cd ~/Movies
 
Comment

Icefire817

macrumors newbie
Original poster
Mar 26, 2011
13
0
WA
I think it just doesn't recognize the file path even with the "cd ~/" because when in terminal it will group up folders that should be separate ones. for example:

Code:
rm: texturesclutterbriefcasedetonatorbriefcasedetonator01_n.dds\r: No such file or directory
When it should be:

Code:
rm: textures/clutter/briefcasedetonator/briefcasedetonator01_n.dds/
 
Comment

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
The trailing \r is because the file as DOS line endings (\r\n) instead of UNIX line endings (\n).

Can you post a sample of these two files?
 
Comment

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Code:
rm: texturesclutterbriefcasedetonatorbriefcasedetonator01_n.dds\r: No such file or directory
What you see at the end there is half of the new line sequence "\r\n" used on Windows, on unix it's '\n' only, so '\r' is interpreted as being part of the filename. You need to strip these of from the names.

Edit:

You can easily add this to what jiminaus posted earlier btw:

Code:
cat dupefilelist.txt | sed 's/\\r//g' | xargs rm
Applies to both rm lines of course.
 
Last edited:
Comment

Icefire817

macrumors newbie
Original poster
Mar 26, 2011
13
0
WA
Well, I added "| sed 's/\\r//g' |" in, but it still does the same thing. Also, i'm not quite sure you got that what I input above was all in terminal. The actual dupefilelist.txt has over a thousand files. A few examples are:
Code:
meshes\ammo\10mmammo.nif
meshes\ammo\308ammo.nif
meshes\ammo\44magnumammo.nif
meshes\ammo\5mmammo.nif
meshes\ammo\alienpowercell.nif
meshes\ammo\eccell.nif
The above path's are exactly like they are found in the file.
So, again, I'm kinda lost. I still think its just that terminal isn't recognizing the file path.
 
Comment

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Well, I added "| sed 's/\\r//g' |" in, but it still does the same thing. Also, i'm not quite sure you got that what I input above was all in terminal.
Of course I do, why else would I suggest sed? 1 file or ten million doesn't matter since it's piped into xargs.

Code:
meshes\ammo\10mmammo.nif
meshes\ammo\308ammo.nif
meshes\ammo\44magnumammo.nif
meshes\ammo\5mmammo.nif
meshes\ammo\alienpowercell.nif
meshes\ammo\eccell.nif
The above path's are exactly like they are found in the file.
So, again, I'm kinda lost. I still think its just that terminal isn't recognizing the file path.
Well there's your problem. You see those are windows file paths (back slash) not the forward slash (/) used in OS X and unix.
 
Comment

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Going on from subsonix, you can also use sed to replace all those Windows backslashes with Unix forwardslashes.

Code:
cat dupefilelist.txt | sed 's/\\r//g' | sed 's/\\/\//g' | xargs rm

Edit: If those sed's are scaring you, you can do that same with tr in a more readable fashion.
Code:
cat dupefilelist.txt | tr -d '\r' | tr '\\' '/' | xargs rm
 
Last edited:
Comment

Icefire817

macrumors newbie
Original poster
Mar 26, 2011
13
0
WA
Well now i'm just a little lost. All I need to do is put in

Code:
cat dupefilelist.txt | sed 's/\\r//g' | sed 's/\\/\//g' | xargs rm
or
Code:
cat dupefilelist.txt | tr -d '\r' | tr '\\' '/' | xargs rm
In with the rest of my command and it should make all of it work? Or do I have to go back and change every single slash in my file.

Edit: Oh, got it now.
Code:
cat dupefilelist.txt | tr -d '\r' | tr '\\' '/' | xargs rm
Worked. it changed all the file path's, but now it still doesn't recognize that the files exist.

Example:
Code:
rm: meshes/ammo/10mmammo.nif: No such file or directory
rm: meshes/ammo/308ammo.nif: No such file or directory
rm: meshes/ammo/44magnumammo.nif: No such file or directory
rm: meshes/ammo/5mmammo.nif: No such file or directory
So, now I am lost again. Some more advice please?
 
Last edited:
Comment

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Those extra codes are fixing your files on-the-fly.

And don't forget to replicate them on the second line as well.
 
Comment

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Example:
Code:
rm: meshes/ammo/10mmammo.nif: No such file or directory
rm: meshes/ammo/308ammo.nif: No such file or directory
rm: meshes/ammo/44magnumammo.nif: No such file or directory
rm: meshes/ammo/5mmammo.nif: No such file or directory
So, now I am lost again. Some more advice please?
Are you in the directory where those files are located? Try:

Code:
ls meshes
If you get "No such file or directory" then you are in the wrong directory or those files does not exist.

Oh btw, you can see your current directory with:

Code:
pwd
 
Last edited:
Comment

Icefire817

macrumors newbie
Original poster
Mar 26, 2011
13
0
WA
Subsonix, I'm not quite sure I understand. Here is what I'm inputting into terminal.


Code:
cd ~/Users/lespeterson/Desktop/RFCW_Temp

cat /Users/lespeterson/Desktop/RFCW_Temp/dupefilelist.txt | tr -d '\r' | tr '\\' '/' | xargs rm
cat /Users/lespeterson/Desktop/RFCW_Temp/dupefolderlist.txt | tr -d '\r' | tr '\\' '/' | xargs rm -rf

chmod 755 $0
The dupefilelist.txt and the Meshes file is in my RFCW_Temp file on my desktop. So, is it that i'm not putting in the right file path at the beginning? Also, when I input pwd into terminal, it tells me that I'm just in:
Code:
/Users/lespeterson
Thanks for being patient with me guys!

Edit: So, I figured I could just move all of my files into my users and that might work then, but to no avail. Same thing came up, even though everything was in my home directory.
 
Last edited:
Comment

sero

macrumors member
Aug 28, 2008
91
14
Your cd command is wrong. The tilde means "/Users/lespeterson" (in your case), so your cd command is saying go to

Code:
/Users/lespeterson/Users/lespeterson/Desktop/RFCW_Temp
Try this

Code:
cd ~/Desktop/RFCW_Temp

cat dupefilelist.txt | tr -d '\r' | tr '\\' '/' | xargs rm
cat dupefolderlist.txt | tr -d '\r' | tr '\\' '/' | xargs rm -rf
 
Comment

Similar threads

  • view60
1
Replies
1
Views
167
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.