Posts: 45
	Threads: 10
	Joined: May 2012
	
	
 
	
	
		Hello,
Someone most likely already asked this or i am just thinking too hard about it.  I want to search for a file that is placed on my desktop, and if i find the file delete it.  What i have so far is
str file "$desktop$\Testing"
;;Was using savedData.getfile(file); err
;;But I realized that was wrong because .getfile reads the data inside the file
;;Was also thinking of something like
if file=file
,out "There is a file"
,del file
else
,out "No such file"
any advice would be grateful
Thank you
	
 
 
	
	
	
		
	Posts: 153
	Threads: 33
	Joined: Aug 2009
	
	
 
	
	
		wouldnt it just be
Macro 
Macro 
if(dir("$desktop$\Testing.txt"))
,del- "$desktop$\Testing.txt"
if need to know all files that are saved in folder can use function GetFilesInFolder
Macro 
Macro2 
str myFolder.expandpath("$desktop$\")
str myFile.from(myFolder "Testing.txt")
ARRAY(str) a; int i
GetFilesInFolder a myFolder
for i 0 a.len
,;out a[i]
,if(a[i]~myFile) 
,,del- myFile; err
 
 
	
	
	
		
	Posts: 153
	Threads: 33
	Joined: Aug 2009
	
	
 
	
	
		maybe better use
if(a[i]=myFile) 
,,del- myFile; err
	
	
	
	
	
 
 
	
	
	
		
	Posts: 45
	Threads: 10
	Joined: May 2012
	
	
 
	
	
		None of those are working.  I tested all all the ways you posted.  To double check that I wasn't messing something up I replaced my "Testing.txt" file with a new "Testing.txt" file on the desktop.  I even did a copy and paste to make sure I didn't do a mistyping.
	
	
	
	
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		Desktop shows files from 2 folders - user desktop and common desktop.
Special folder $desktop$ is user desktop folder.
Special folder $common desktop$ is common desktop folder. Try it.
this macro shows files in both folders
Macro 
Macro1788 
out " ----------- files in user desktop folder"
Dir du
foreach(du "$desktop$\*" FE_Dir)
,str sPath=du.FileName(1)
,out sPath
out " ----------- files in common desktop folder"
Dir dc
foreach(dc "$common desktop$\*" FE_Dir)
,str sPath2=dc.FileName(1)
,out sPath2
 
 
	
	
	
		
	Posts: 45
	Threads: 10
	Joined: May 2012
	
	
 
	
	
		I noticed that it only showed files instead of both files and folders.  I was trying to edit it so that it would show both files and folders, but i couldn't get it to work.  Any advice on how to do it?
	
	
	
	
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		Use dialog "Enumerate files" or "If file exists". They are in the floating toolbar.
Macro 
Macro1788 
out " ----------- files and folders in user desktop folder"
Dir du
foreach(du "$desktop$\*" FE_Dir 2)
,str sPath=du.FileName(1)
,out sPath
out " ----------- files and folders in common desktop folder"
Dir dc
foreach(dc "$common desktop$\*" FE_Dir 2)
,str sPath2=dc.FileName(1)
,out sPath2
 
 
	
	
	
		
	Posts: 153
	Threads: 33
	Joined: Aug 2009
	
	
 
	
	
		Sorry. Didnt think of the second folder but noticed that the expandpath("$desktop$\")  part is uneeded, correct?
	
	
	
	
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		Need expandpath only if you'll use the path with non-QM functions, ie dll and COM functions. Here not necessary.
	
	
	
	
	
 
 
	
	
	
		
	Posts: 45
	Threads: 10
	Joined: May 2012
	
	
 
	
	
		Thank you Gintaras and MAGNET for the info help a lot
	
	
	
	
	
 
 
	
	
	
		
	Posts: 45
	Threads: 10
	Joined: May 2012
	
	
 
	
	
		Hello again,
I was wondering how i would set up comparing 2 different folders to see if the content is the same or not.  I tried to use
Dir du
foreach(du "$desktop$\Foler2\*" FE_Dir 2)
,str sPath=du.FileName(1)
foreach(du "$desktop$\Foler1\*" FE_Dir 2)
,str sPath1=du.FileName(1)
if sPath1=sPath
,out "Same"
else
,out "Different"
the outcome is always "Different", except for the the folders are empty.
What am I doing wrong?
Help would be grateful,
Thank you
	
 
 
	
	
	
		
	Posts: 12,239
	Threads: 144
	Joined: Dec 2002
	
	
 
	
	
		Try this. Not tested.
Macro 
Macro1810 
ARRAY(str) a1 a2
GetFilesInFolder a1 "$desktop$\Foler1"
GetFilesInFolder a2 "$desktop$\Foler2"
a1.sort(2)
a2.sort(2)
str s1 s2
s1=a1
s2=a2
if s1~s2
,out "Same"
else
,out "Different"