Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching for folder
#1
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
Code:
Copy      Help
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
#2
wouldnt it just be

Macro Macro
Code:
Copy      Help
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
Code:
Copy      Help
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
#3
maybe better use

if(a[i]=myFile)
,,del- myFile; err
#4
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.
#5
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
Code:
Copy      Help
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
#6
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?
#7
Use dialog "Enumerate files" or "If file exists". They are in the floating toolbar.

Macro Macro1788
Code:
Copy      Help
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
#8
Sorry. Didnt think of the second folder but noticed that the expandpath("$desktop$\") part is uneeded, correct?
#9
Need expandpath only if you'll use the path with non-QM functions, ie dll and COM functions. Here not necessary.
#10
Thank you Gintaras and MAGNET for the info help a lot
#11
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
Code:
Copy      Help
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
#12
Try this. Not tested.
Macro Macro1810
Code:
Copy      Help
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"


Forum Jump:


Users browsing this thread: 1 Guest(s)